package com.yuanfeng.order.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.yuanfeng.commoms.config.YFConfig;
import com.yuanfeng.commoms.constant.CommonStatusEnum;
import com.yuanfeng.commoms.constant.CommonType;
import com.yuanfeng.commoms.dto.goods.ActivityGoodsDetailDTO;
import com.yuanfeng.commoms.dto.goods.ManjianzengzheGoodsRuleQueryDTO;
import com.yuanfeng.commoms.dto.order.ConsumeRecordByBusinessDTO;
import com.yuanfeng.commoms.dto.order.ConsumeRecordParaDTO;
import com.yuanfeng.commoms.dto.order.ConsumeTradeParaDTO;
import com.yuanfeng.commoms.exception.BizCodeEnume;
import com.yuanfeng.commoms.util.*;
import com.yuanfeng.commoms.util.Json.JsonUtils;
import com.yuanfeng.commoms.vo.activity.*;
import com.yuanfeng.commoms.vo.fx.VKUserInfoVO;
import com.yuanfeng.commoms.vo.goods.WapGoodsSaleSumUpdateVO;
import com.yuanfeng.commoms.vo.order.*;
import com.yuanfeng.commoms.vo.shop.ShippingListVO;
import com.yuanfeng.commoms.vo.shop.ShopParaVO;
import com.yuanfeng.commoms.vo.shop.ShopUserMessageResultVO;
import com.yuanfeng.commoms.vo.user.UserInfoVO;
import com.yuanfeng.order.dto.CreateOrderDTO;
import com.yuanfeng.order.dto.ManjianzengzheDTO;
import com.yuanfeng.order.dto.PriceDTO;
import com.yuanfeng.order.dto.SubclassDTO;
import com.yuanfeng.order.entity.OrderBaseEntity;
import com.yuanfeng.order.feign.*;
import com.yuanfeng.order.mapper.*;
import com.yuanfeng.order.service.FXService;
import com.yuanfeng.order.service.OrderCreateService;
import com.yuanfeng.order.vo.OrderInfoVO;
import io.seata.core.context.RootContext;
import io.seata.core.exception.TransactionException;
import io.seata.tm.api.GlobalTransactionContext;
import org.apache.commons.collections.map.HashedMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.CollectionUtils;
import redis.clients.jedis.Jedis;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @ClassName OrderCreateServiceImpl
 * @Description 创建订单 计算价格
 * @Author cyp
 * @Date 2023-05-26 13:28:35
 * @Version 1.0
 **/
@Service
public class OrderCreateServiceImpl implements OrderCreateService {

    private static final Logger LOG = LoggerFactory.getLogger(OrderCreateService.class);
    @Autowired
    private GoodServiceClient goodServiceClient;
    @Autowired
    private BusinessServiceClient businessServiceClient;
    @Autowired
    private UserServiceClient userServiceClient;
    @Autowired
    private ActivityServiceClient activityServiceClient;
    @Autowired
    private BaseServiceClient baseServiceClient;
    @Autowired
    private OrderInvoiceInfoMapper orderInvoiceInfoMapper;
    @Autowired
    private OrderGoodsMapper orderGoodsMapper;
    @Autowired
    private OrderBaseMapper orderBaseMapper;
    @Autowired
    private FXService fxService;
    @Autowired
    private PayMentServiceClient payMentServiceClient;
    @Autowired
    private OrderUserCartMapper orderUserCartMapper;
    @Autowired
    private OrderCommissionMapper orderCommissionMapper;


    @Override
    public ResponseResult calculatePrice(String message) {
        LOG.info("message{}", message);
        ResponseResult rr = new ResponseResult();
        rr = businessServiceClient.queryShipping(message);
        if (rr.getCode() != CommonStatusEnum.SUCCESS.getCode()) {
            return rr;
        }
        String goodsDetails = rr.getData().toString();
        // json转对象
        List<WapShopShippingQueryResultVO> wapList = JSON.parseObject(goodsDetails, new TypeReference<List<WapShopShippingQueryResultVO>>() {
        });
        BigDecimal couponTotalPrice = new BigDecimal(0);// 总优惠券金额
        BigDecimal totalPrice = new BigDecimal(0);// 总价(实付金额+运费-扣除红包消费券之后的价格)
        BigDecimal allShopTotalPrice = new BigDecimal(0);// 所有店铺价格(不含运费与优惠价格)
        BigDecimal allowancePrice = BigDecimal.ZERO;// 跨店满减总商品价格
        BigDecimal totalShipping = new BigDecimal(0);// 总运费
        BigDecimal goodsTotalPrice = new BigDecimal(0);// 商品总价
        BigDecimal hiuYuanZhekoutotal = new BigDecimal(0);// 会员折扣总优惠
        Integer activityStatus = null;// 商品优惠方式
        //HashSet<Integer> mjzzIds = new HashSet<Integer>();// 满减赠折活动ID
        HashSet<ManjianzengzheDTO> mjzzIds = new HashSet<>();// 满减赠折活动ID
        Map<Integer, BigDecimal> mjzzAmounts = new HashMap<Integer, BigDecimal>(); // 满减赠折每个活动累计金额
        Map<Integer, Integer> mzNum = new HashMap<Integer, Integer>(); // 满折件数
        Map<Integer, Object> mjzzRules = new HashMap<Integer, Object>();// 满减赠折每个活动的规则
        Integer judgeStatus = null;
        List<ShippingListVO> shippingList = new ArrayList<ShippingListVO>();
        ShopParaVO sp = new ShopParaVO();
        //满减赠折优惠总金额初始化，默认值为0
        sp.setTotalManjianDiscount(BigDecimal.ZERO);//总满减优惠金额
        sp.setTotalManzheDiscount(BigDecimal.ZERO);//总满折优惠金额
        CommonParameterVO cp = new CommonParameterVO();
        cp = JSON.parseObject(message, new TypeReference<CommonParameterVO>() {
        });
        String token = cp.getToken();
        String userInfoStr = RedisUtil.get(YFConfig.YF_USER_TOKEN_USERID + token);
        if (userInfoStr == null || userInfoStr.equals("")) {
            return ResponseResult.fail(BizCodeEnume.TOKEN_IS_ILLEGAL.getMsg());
        }
        String userId = null;
        UserInfoVO userInfo = ParseTokenUtils.getUserInfoByToken(token);
        userId = userInfo.getUserId();

        //查询用户是否开通plus会员 并且是否有折扣权益
        BigDecimal usedamout = new BigDecimal(0);
        ResponseResult selectplusmember = userServiceClient.queryUserPlusInfo(userId);
        BigDecimal plusDiscount = null;//plus会员折扣
        BigDecimal plusResidualLimit = null;//plus会员剩余可用额度
        if (selectplusmember.getCode() == 1) {
            Map<String, Object> userPlusInfo = (Map<String, Object>) selectplusmember.getData();
            plusDiscount = new BigDecimal(userPlusInfo.get("discount").toString());
            plusResidualLimit = new BigDecimal(userPlusInfo.get("residualLimit").toString());
            usedamout = plusResidualLimit;//剩余可用额度
        }

        //pans 是否是积分商品
        if (null != cp.getIntegralGoods() && 0 == cp.getIntegralGoods()) {
            //获取店铺列表
            List<StoreInformationVO> storeInformationList = cp.getStoreInformationList();
            for (StoreInformationVO storeInformation : storeInformationList) {
                //获取商品列表
                List<GoodsInformationVO> goodsBaseList = storeInformation.getGoodsBaseList();
                for (GoodsInformationVO goodsInformation : goodsBaseList) {
                    Integer goodsId = goodsInformation.getGoodsId();
                    Map<String, Object> map = new HashMap<>();
                    map.put("goodsId", goodsId);
                    //根据goodsId查询 积分商品的价格 所需积分 库存
                    ResponseResult resp = goodServiceClient.queryIntegralGoodsBygoodsId(map);
                    Map<String, Object> resmap = (Map<String, Object>) resp.getData();
                    Integer goodsStock = (Integer) resmap.get("goodsStock");//库存
                    Integer needIntegral = (Integer) resmap.get("needIntegral");//所需积分
                    Double goodsPrice = (Double) resmap.get("goodsPrice");//价格
                    BigDecimal goodsPrice2 = new BigDecimal(goodsPrice);
                    if (null != goodsInformation.getGoodsNum() && goodsInformation.getGoodsNum() <= goodsStock) {
                        //积分商品不为null qie不为0
                        if (null != goodsPrice2 && (goodsPrice2.compareTo(new BigDecimal(0)) == 1)) {
                            //购买的商品数量乘于商品价格
                            sp.setTotalPrice(goodsPrice2.multiply(new BigDecimal(goodsInformation.getGoodsNum())));
                        }
                        //购买的商品数量乘于购买所需的积分
                        sp.setTotalIntegral(needIntegral * goodsInformation.getGoodsNum());
                        ShippingListVO sl = new ShippingListVO();// 存放shopId&&每家店铺运费
                        sl.setShopId(0);
                        sl.setGoodsNo(1);
                        sl.setShopLimit(null);// 存放店铺红包id
                        sl.setShipping(new BigDecimal(0));
                        sl.setGoodsIdList(null);
                        sl.setGoodsCatLimit(null);// 存放单品红包id
                        sl.setRedpacketTType(null);
                        sl.setGoodsQuantity(0);
                        sl.setShopPrice(new BigDecimal(goodsPrice).multiply(new BigDecimal(goodsInformation.getGoodsNum())));
                        sl.setReceivingTime(new BigDecimal(72));
                        sl.setCouponPrice(new BigDecimal(0));
                        sl.setAllowanceShopId("");
                        sl.setItemShopId(null);
                        sl.setGoodsNo(1);
                        sl.setItemShopPrice(new BigDecimal(0));
                        sl.setAllowanceShopPrice(new BigDecimal("0"));
                        sl.setShopTotalPrice(new BigDecimal(goodsPrice));
                        shippingList.add(sl);
                        sp.setShippingList(shippingList);
                        rr.setCode(1);
                        rr.setData(sp);
                        rr.setMessage("");
                    } else {
                        rr.setCode(2);
                        rr.setMessage("库存不足");
                    }
                    return rr;
                }
            }
        }
        // 获取红包Id,并封装Map,在向malls请求数据
        Map<String, String> redPacketIdMap = new HashMap<>();
        Integer redPacketNo = cp.getRedPacketId();// 红包id
        String voucherId = null;// 优惠券id
        BigDecimal platformVoucherPrice = new BigDecimal(0);// 平台优惠券金额
        List<Integer> avaliableGoods = new ArrayList<>();
        Integer couponNo = null;
        BigDecimal redPacketPrice = new BigDecimal(0);
        BigDecimal couponPrice = new BigDecimal(0);
        BigDecimal orderLimit = new BigDecimal(0);// 红包订单限额
        String redpacketId = null;// 红包编码
        Integer platFormVoucherId = null;// 平台优惠券id
        String shopLimit = null;// 店铺红包id
        Integer redPacketStatus = null;// 红包使用状态
        Integer voucherStatus = null;// 优惠券使用状态
        Integer redpacketTType = null;

        BigDecimal plusgoodsprice = new BigDecimal(0);// 计算plus会员折扣用
        BigDecimal plusgoodstotal = new BigDecimal(0);// 计算plus会员总折扣

        List<String> voucherIdList = new ArrayList<>();
        YfRedpacketBaseVO redPacket = new YfRedpacketBaseVO();
        if (redPacketNo != 0) {
            String redPacketId = redPacketNo.toString();
            redPacketIdMap.put("redpacketId", redPacketId);
            // 创建接收bea
            redPacket = activityServiceClient.getRedpDetail(redPacketIdMap);

            redpacketTType = redPacket.getRedpacketTType();
            shopLimit = redPacket.getShopLimit();// 获取店铺红包id
            redPacketStatus = redPacket.getRedpacketState();// 红包使用状态
            Integer redpacketTOrderlimit = redPacket.getRedpacketTOrderlimit();// 使用红包订单限额
            orderLimit = new BigDecimal(redpacketTOrderlimit.toString());// 类型转换

            // 获取红包价格
            redPacketPrice = new BigDecimal(redPacket.getRedpacketPrice());
            // 获取红包编码
            redpacketId = redPacket.getRedpacketId().toString();
        }
        try {
            platFormVoucherId = cp.getVoucherId();
            String platFormCouponsId = platFormVoucherId.toString();
            Map<String, Object> voucherTIdMap = new HashMap<>();
            if (platFormCouponsId != null && !"0".equals(platFormCouponsId)) {
                // 当参数不为空时，则使用平台优惠券
                System.out.println("-----Enter-----");
                voucherTIdMap.put("voucherId", platFormCouponsId);
                // 创建接收bean
                VoucherBaseVO voucher = activityServiceClient.getVoucherDetail(voucherTIdMap);
                // 获取平台优惠券id
                sp.setPlatformVoucherCode(platFormCouponsId);
                // 获取优惠券价格
                platformVoucherPrice = new BigDecimal(voucher.getVoucherPrice());
                sp.setPlatformVoucherPrice(platformVoucherPrice);
                avaliableGoods = voucher.getAvaliableGoods();// 参加平台优惠券商品id
                sp.setAvaliableGoods(avaliableGoods);
            } else {
                platformVoucherPrice = new BigDecimal(0);
                sp.setPlatformVoucherPrice(platformVoucherPrice);
                avaliableGoods = null;
                sp.setAvaliableGoods(avaliableGoods);
            }
        } catch (Exception e) {
            System.out.println("-----voucherTIdIsNull-----" + e.getMessage());
        }
        List<BigDecimal> memberDiscountList = new ArrayList<>();
        List<BigDecimal> plusDiscountList = new ArrayList<>();
        // 根据店铺循环
        for (int i = 0; i < wapList.size(); i++) {//ZZZ:店铺循环开始，s1存放每个店铺的信息
            ShippingListVO sl = new ShippingListVO();// 存放shopId&&每家店铺运费
            BigDecimal shopPrice = new BigDecimal(0);// 各店铺总价(不含运费与优惠价格)
            BigDecimal itemShopPrice = BigDecimal.ZERO;// 参加红包活动总价
            BigDecimal allowanceShopPrice = BigDecimal.ZERO;// 参加购物津贴活动总价
            Integer shopId = wapList.get(i).getShopId();
            BigDecimal shippingFee = wapList.get(i).getShippingFee();// 店铺运费
            sl.setShopId(shopId);
            sl.setShopLimit(shopLimit);// 存放店铺红包id
            sl.setShipping(shippingFee);
            sl.setRedpacketTType(redpacketTType);
            sl.setShopManjianDiscount(BigDecimal.ZERO);//店铺满减金额
            sl.setShopManzheDiscount(BigDecimal.ZERO);//店铺满折金额

            BigDecimal shopTotalPrice = new BigDecimal(0);// 每家店铺总价格
            Integer goodsNo = 0;// 商品数量
            Integer goodsQuantity = 0;// 参加多品红包商品数量
            List<BigDecimal> goodsAmountList = new ArrayList<>();
            List<Integer> hyORstep = new ArrayList<>();
            List<GoodsInformationVO> goodsBaseList = new ArrayList<>(); //优惠券商品
            // 获取商品
            List<WapShopShippingResultVO> wssrList = wapList.get(i).getGoodsBaseList();//ZZZ:获取每个店铺下的所有商品
            for (int n = 0; n < wssrList.size(); n++) {//ZZZ:遍历店铺商品
                List<WapShippingQueryResultVO> wsqrList = wssrList.get(n).getGoodsBaseList();//ZZZ：获取不同包裹底下的所有商品

                for (WapShippingQueryResultVO wapShippingQueryResultVO : wsqrList) {//ZZZ:遍历包裹商品
                    Integer commodityId = wapShippingQueryResultVO.getGoodsId();
                    Integer goodsMaxSale = wapShippingQueryResultVO.getGoodsMaxSale();
                    Integer goodsStock = wapShippingQueryResultVO.getGoodsStock();
                    Integer goodsNumber = wapShippingQueryResultVO.getGoodsNum();
                    BigDecimal goodsPrice = BigDecimal.ZERO;
                    activityStatus = wapShippingQueryResultVO.getActivityStatus();
                    ActivityGoodsDetailDTO agd = wapShippingQueryResultVO.getActivityGoodsDetail();
                    Integer commonType = wapShippingQueryResultVO.getCommonType();
                    // 查询店铺发货时长
                    BigDecimal shippingTime = orderBaseMapper.queryShippingTimeByGoods(shopId, wapShippingQueryResultVO.getGoodsId());
                    if (shippingTime != null) {
                        BigDecimal receivingTime = shippingTime.setScale(0, RoundingMode.HALF_UP);
                        sl.setReceivingTime(receivingTime);
                    } else {
                        BigDecimal receivingTime = new BigDecimal(72);
                        sl.setReceivingTime(receivingTime);
                    }
                    if (commonType == 1) {
                        if (activityStatus == 1) {

                        } else if (activityStatus == 2) {
                            hyORstep.add(2);
                            HashMap<String, Object> map = new HashMap<>();
                            map.put("token", token);
                            map.put("goodsId", wapShippingQueryResultVO.getGoodsId());
                            ResponseResult checkLimit = activityServiceClient.seckillCheckLimit(map);
                            if (checkLimit.getCode() == 1) {
                                goodsPrice = agd.getActivityPrice();
                            } else if (checkLimit.getCode() == 2) {
                                goodsPrice = wapShippingQueryResultVO.getGoodsPrice();
                            } else {
                                rr.setCode(3);
                                rr.setMessage("token失效，请重新登录");
                                return rr;
                            }
                            // 秒杀
                            String goodsId = wapShippingQueryResultVO.getGoodsId().toString();
                            goodsNumber = wapShippingQueryResultVO.getGoodsNum();
                            BigDecimal goodsNum = new BigDecimal(goodsNumber);
                            BigDecimal price = goodsPrice.multiply(goodsNum);// 付款价格(不包含运费)

                            if (platFormVoucherId != null && platFormVoucherId != 0
                                    && avaliableGoods.contains(Integer.parseInt(goodsId))) {
                                allowancePrice = allowancePrice.add(price);
                                allowanceShopPrice = allowanceShopPrice.add(price);
                                sl.setAllowanceShopId(shopId.toString());
                            } else {
                                sl.setAllowanceShopId("");
                            }
                            // 商品小计
                            goodsAmountList.add(price);
                            sl.setGoodsAmountList(goodsAmountList);
                            plusgoodsprice = price; //plus会员折扣价
                            shopTotalPrice = shopTotalPrice.add(price);
                            goodsTotalPrice = goodsTotalPrice.add(price);
                            shopPrice = shopPrice.add(price);
                            goodsNo = goodsNo + goodsNumber;
                            sl.setGoodsQuantity(goodsQuantity);
                            sl.setGoodsNo(goodsNo);
                        } else if (activityStatus == 3) {
                            hyORstep.add(3);
                            HashMap<String, Object> map = new HashMap<>();
                            map.put("token", token);
                            map.put("goodsId", wapShippingQueryResultVO.getGoodsId());
                            ResponseResult checkLimit = activityServiceClient.discountCheckLimit(map);
                            if (checkLimit.getCode() == 1) {
                                goodsPrice = agd.getActivityPrice();
                            } else if (checkLimit.getCode() == 2) {
                                goodsPrice = wapShippingQueryResultVO.getGoodsPrice();
                            } else {
                                rr.setCode(3);
                                rr.setMessage("token失效，请重新登录");
                                return rr;
                            }
                            // 限时折扣
                            String goodsId = wapShippingQueryResultVO.getGoodsId().toString();
                            goodsNumber = wapShippingQueryResultVO.getGoodsNum();
                            BigDecimal goodsNum = new BigDecimal(goodsNumber);
                            BigDecimal price = goodsPrice.multiply(goodsNum);// 付款价格(不包含运费)
                            if (platFormVoucherId != null && platFormVoucherId != 0
                                    && avaliableGoods.contains(Integer.parseInt(goodsId))) {
                                allowancePrice = allowancePrice.add(price);
                                allowanceShopPrice = allowanceShopPrice.add(price);
                                sl.setAllowanceShopId(shopId.toString());
                            } else {
                                sl.setAllowanceShopId("");
                            }
                            // 商品小计
                            goodsAmountList.add(price);
                            sl.setGoodsAmountList(goodsAmountList);
                            plusgoodsprice = price; //plus会员折扣价

                            shopTotalPrice = shopTotalPrice.add(price);
                            goodsTotalPrice = goodsTotalPrice.add(price);
                            shopPrice = shopPrice.add(price);
                            goodsNo = goodsNo + goodsNumber;
                            sl.setGoodsQuantity(goodsQuantity);
                            sl.setGoodsNo(goodsNo);
                        } else if (activityStatus == 4 && cp.getPlatForm() != null && cp.getPlatForm() != 1) {
                            hyORstep.add(4);
                            // 拼团
                            if (agd.getType() == 0) {
                                goodsPrice = agd.getPintuanPrice();
                            } else {
                                goodsPrice = agd.getPriceOne();
                            }
                            goodsNumber = wapShippingQueryResultVO.getGoodsNum();
                            BigDecimal goodsNum = new BigDecimal(goodsNumber);
                            BigDecimal price = goodsPrice.multiply(goodsNum);// 付款价格(不包含运费)
                            shopTotalPrice = shopTotalPrice.add(price);

                            // 商品小计
                            goodsAmountList.add(price);
                            sl.setGoodsAmountList(goodsAmountList);
                            plusgoodsprice = price; //plus会员折扣价

                            goodsTotalPrice = goodsTotalPrice.add(price);
                            shopPrice = shopPrice.add(price);
                            goodsNo = goodsNo + goodsNumber;
                            sl.setGoodsNo(goodsNo);
                        } else if (activityStatus == 5) {
                            hyORstep.add(5);
                            // 满减赠折
                            goodsPrice = wapShippingQueryResultVO.getGoodsPrice();
                            goodsNumber = wapShippingQueryResultVO.getGoodsNum();
                            BigDecimal goodsNum = new BigDecimal(goodsNumber);
                            BigDecimal price = goodsPrice.multiply(goodsNum);// 付款价格(不包含运费)
                            Integer promotionId = agd.getPromotionId();//满减赠折活动ID
                            List<ManjianzengzheGoodsRuleQueryDTO> ruleList = agd.getRuleList();//满减赠折活动规则
                            ManjianzengzheDTO dto = new ManjianzengzheDTO();
                            List<Integer> indexList = new ArrayList<>();
                            indexList.add(n);
                            List<Integer> goodsIdList = new ArrayList<>();
                            goodsIdList.add(wapShippingQueryResultVO.getGoodsId());
                            List<BigDecimal> goodsPriceList = new ArrayList<>();
                            goodsPriceList.add(price);
                            dto.setGoodsId(wapShippingQueryResultVO.getGoodsId());
                            dto.setPromotionId(promotionId);
                            dto.setIndexList(indexList);
                            dto.setIndex(n);
                            dto.setGoodsIdList(goodsIdList);
                            dto.setGoodsPriceList(goodsPriceList);
                            if (!mjzzIds.isEmpty()) {
                                List<Integer> mjIdList = mjzzIds.stream().map(ManjianzengzheDTO::getPromotionId).collect(Collectors.toList());
                                if (!mjIdList.contains(promotionId)) {
                                    mjzzIds.add(dto);// 收集满减赠折活动ID
                                } else {
                                    HashSet<ManjianzengzheDTO> newSet = new HashSet<>();
                                    for (ManjianzengzheDTO mjDto : mjzzIds) {
                                        if (!mjDto.getPromotionId().equals(promotionId)) {
                                            newSet.add(mjDto);
                                        } else {
                                            indexList.addAll(mjDto.getIndexList());
                                            dto.setIndexList(indexList);
                                            goodsIdList.addAll(mjDto.getGoodsIdList());
                                            dto.setGoodsIdList(goodsIdList);
                                            goodsPriceList.addAll(mjDto.getGoodsPriceList());
                                            dto.setGoodsPriceList(goodsPriceList);
                                        }
                                    }
                                    newSet.add(dto);
                                    mjzzIds = newSet;
                                }
                            } else {
                                mjzzIds.add(dto);// 收集满减赠折活动ID
                            }
                            // 收集满减赠折每个活动的累计金额
                            if (null == mjzzAmounts.get(promotionId)) {
                                mjzzAmounts.put(promotionId, price);
                            } else {
                                BigDecimal tmp = mjzzAmounts.get(promotionId).add(price);
                                mjzzAmounts.put(promotionId, tmp);
                            }
                            //收集满减赠折每个活动的活动规则
                            mjzzRules.putIfAbsent(promotionId, ruleList);
                            //收集满赠活动商品数量
                            if (3 == ruleList.get(0).getDiscountType()) {
                                if (null == mzNum.get(promotionId)) {
                                    mzNum.put(promotionId, goodsNumber);
                                } else {
                                    Integer tmpNum = mzNum.get(promotionId) + goodsNumber;
                                    mzNum.put(promotionId, tmpNum);
                                }

                            }
                            // 商品小计
                            goodsAmountList.add(price);
                            sl.setGoodsAmountList(goodsAmountList);
                            plusgoodsprice = price; //plus会员折扣价

                            shopTotalPrice = shopTotalPrice.add(price);
                            goodsTotalPrice = goodsTotalPrice.add(price);
                            shopPrice = shopPrice.add(price);
                            goodsNo = goodsNo + goodsNumber;
                            sl.setGoodsNo(goodsNo);
                        } else {
                            hyORstep.add(0);
                            String goodsId = wapShippingQueryResultVO.getGoodsId().toString();
                            goodsNumber = wapShippingQueryResultVO.getGoodsNum();
                            BigDecimal goodsNum = new BigDecimal(goodsNumber);
                            goodsPrice = wapShippingQueryResultVO.getGoodsPrice();
                            BigDecimal price = goodsPrice.multiply(goodsNum);// 付款价格(不包含运费)
                            if (platFormVoucherId != null && platFormVoucherId != 0
                                    && avaliableGoods.contains(Integer.parseInt(goodsId))) {
                                allowancePrice = allowancePrice.add(price);
                                allowanceShopPrice = allowanceShopPrice.add(price);
                                sl.setAllowanceShopId(shopId.toString());
                            } else {
                                sl.setAllowanceShopId("");
                            }
                            // 商品小计
                            goodsAmountList.add(price);
                            sl.setGoodsAmountList(goodsAmountList);
                            plusgoodsprice = price; //plus会员折扣价

                            goodsTotalPrice = goodsTotalPrice.add(price);
                            shopTotalPrice = shopTotalPrice.add(price);
                            shopPrice = shopPrice.add(price);
                            goodsNo = goodsNo + goodsNumber;
                            sl.setGoodsQuantity(goodsQuantity);
                            sl.setGoodsNo(goodsNo);
                        }

                        BigDecimal memberDiscount = goodsPrice;
                        //总商品价格减去总运费  得出总的商品价格
                        if (null != cp.getMemberClassId() && 0 != cp.getMemberClassId()) {
                            BigDecimal hiuYuanZhekou = plusgoodsprice;//商品价格                        //会员折扣
                            //根据会员的会员等级id 查询出会员折扣
                            ResponseResult resp = baseServiceClient.getMemberNameByClassId(cp.getMemberClassId().toString());
                            Map<String, Object> map = (Map<String, Object>) resp.getData();
                            Double gradeDiscount = (Double) map.get("gradeDiscount");
                            memberDiscount = memberDiscount.subtract(memberDiscount.multiply(new BigDecimal(gradeDiscount)).setScale(2, RoundingMode.HALF_UP));
                            //计算出使用会员折扣，折扣了多少钱
                            hiuYuanZhekou = hiuYuanZhekou.subtract(hiuYuanZhekou.multiply(new BigDecimal(gradeDiscount)).setScale(2, RoundingMode.HALF_UP));
                            memberDiscountList.add(hiuYuanZhekou);
                            hiuYuanZhekoutotal = hiuYuanZhekoutotal.add(hiuYuanZhekou);
                            plusgoodsprice = plusgoodsprice.subtract(hiuYuanZhekou);
                        }else {
                            memberDiscountList.add(BigDecimal.ZERO);
                        }
                        BigDecimal plusMemberDiscount = memberDiscount;
                        //计算plus会员折扣金额
                        //查询是否为plus商品
                        if (selectplusmember.getCode() == 1 && (cp.getPlatForm() != null && cp.getPlatForm() == 1)) {
                            Integer integer = goodServiceClient.queryGoodsIsPlus(wapShippingQueryResultVO.getCommonId());
                            if (integer == 1) {
                                BigDecimal data = plusDiscount;//plus会员折扣
                                data = new BigDecimal(1).subtract(data);
                                BigDecimal multiply = plusgoodsprice.multiply(data);//plus商品会员折扣金额

                                //判断可用额度
                                if (usedamout.compareTo(new BigDecimal(-1)) != 0) {
                                    if (multiply.compareTo(usedamout) > 0) {//剩余额度不足
                                        multiply = usedamout;
                                    }
                                    plusMemberDiscount = multiply.divide( BigDecimal.valueOf(goodsNumber),2,RoundingMode.HALF_UP);
                                    if(plusMemberDiscount.multiply(BigDecimal.valueOf(goodsNumber)).compareTo(multiply) != 0){
                                        multiply = plusMemberDiscount.multiply(BigDecimal.valueOf(goodsNumber));
                                    }
                                    usedamout = usedamout.subtract(multiply);
                                }

                                BigDecimal add = plusgoodstotal.add(multiply);
                                plusDiscountList.add(plusMemberDiscount);
                                plusgoodstotal = add.setScale(2, RoundingMode.HALF_UP);//plus会员总折扣
                            }else{
                                plusDiscountList.add(BigDecimal.ZERO);
                            }
                        }else{
                            plusDiscountList.add(BigDecimal.ZERO);
                        }
                        // 优惠券商品
                        if (cp.getIsAutoChoose() != null && cp.getIsAutoChoose() == 1) {
                            GoodsInformationVO voucherGoods = new GoodsInformationVO();
                            voucherGoods.setGoodsId(commodityId);
                            voucherGoods.setGoodsNum(goodsNumber);
                            voucherGoods.setGoodsPrice(Double.valueOf(goodsPrice.subtract(memberDiscount).subtract(plusMemberDiscount).setScale(2, RoundingMode.HALF_UP).toString()));
                            goodsBaseList.add(voucherGoods);
                        }
                    }

                    // 判断商品是否有最大库存数量
                    if (goodsNumber > goodsStock) {
                        judgeStatus = 1;
                        rr.setCode(2);
                        rr.setData(null);
                        rr.setMessage("当前商品数量超过库存数量!");
                    } else {
                        judgeStatus = 0;
                    }
                }
            }
            // 先计算会员折扣再计算优惠券
            String voucherNo = cp.getStoreInformationList().get(i).getCouponId();
            if (cp.getIsAutoChoose() != null && cp.getIsAutoChoose() == 1) {
                Map<String, Object> voucherPara = new HashMap<>();
                voucherPara.put("token",cp.getToken());
                voucherPara.put("platForm",cp.getPlatForm());
                voucherPara.put("shopId",shopId);
                voucherPara.put("goodsInfo",goodsBaseList);
                ResponseResult voucherResp = activityServiceClient.selectAvailableVcBase(voucherPara);
                List<YfVoucherBaseVO> voucherBaseVOList = JSON.parseArray(JSON.toJSONString(voucherResp.getData()),YfVoucherBaseVO.class);
                if(!voucherBaseVOList.isEmpty()){
                    voucherNo = voucherBaseVOList.get(0).getVoucherNo();
                    sl.setVoucherTitle(voucherBaseVOList.get(0).getVoucherTitle());
                }
            }
            if(!voucherNo.equals("0")) {
                String[] voucherNoList = voucherNo.split("-");
                for (String no : voucherNoList) {
                    // 获取代金券Id,并封装Map,在向malls请求数据
                    Map<String, Object> couponIdMap = new HashMap<>();
                    couponNo = Integer.parseInt(no);
                    // couponNo = cp.getStoreInformationList().get(i).getCouponId();
                    String couponId = couponNo.toString();
                    couponIdMap.put("voucherId", couponId);
                    // 创建接收bean
                    VoucherBaseVO voucher = activityServiceClient.getVoucherDetail(couponIdMap);
                    // 获取优惠券价格
                    couponPrice = couponPrice.add(BigDecimal.valueOf(voucher.getVoucherPrice()));
                    voucherStatus = voucher.getVoucherState();// 优惠券使用状态
                    sl.setVoucherTitle(voucherNoList.length > 1 ? "组合优惠" : voucher.getVoucherTitle());
                }
                sl.setCouponPrice(couponPrice);
                sl.setVoucherStatus(voucherStatus);
            }else{
                couponNo = 0;
                couponPrice = new BigDecimal(0);
                sl.setCouponPrice(couponPrice);
            }
            sl.setVoucherId(voucherNo);
            couponTotalPrice = couponTotalPrice.add(couponPrice);
            voucherIdList.add(voucherNo);// 存放优惠券集合
            //如果是 自提商品运费为0
            if (null != cp.getOrderIsShopTake() && 1 == cp.getOrderIsShopTake()) {
                shippingFee = new BigDecimal(0);
            }
            totalShipping = totalShipping.add(shippingFee);
            goodsTotalPrice = goodsTotalPrice.add(shippingFee);
            sl.setPromotionIdList(hyORstep);
            try {
                //ZZZ处理每家店铺的满减赠折优惠内容
                DealMjzzPromotion(sp, sl, mjzzIds, mjzzAmounts, mjzzRules, mzNum);
            } catch (Exception e) {
                e.printStackTrace();
            }
            sl.setMemberDiscountList(memberDiscountList);
            sl.setPlusDiscountList(plusDiscountList);
            sl.setShopPrice(shopPrice);
            sl.setItemShopPrice(itemShopPrice);
            sl.setAllowanceShopPrice(allowanceShopPrice);
            sl.setShopTotalPrice(shopTotalPrice.add(shippingFee).subtract(couponPrice));
            shippingList.add(sl);
            allShopTotalPrice = allShopTotalPrice.add(shopPrice);// 所有店铺总价
            //每个店铺结束清理满减赠折优惠信息
            mjzzRules.clear();
            mjzzAmounts.clear();
            mjzzIds.clear();
        }//ZZZ:店铺循环结束

        // 店铺总商品总金额
        totalPrice = totalPrice.add(goodsTotalPrice);
        totalPrice = totalPrice.subtract(hiuYuanZhekoutotal).subtract(plusgoodstotal);
        sp.setMemberDiscountAmount(hiuYuanZhekoutotal);
        totalPrice = totalPrice.subtract(couponTotalPrice).subtract(platformVoucherPrice)
                .subtract(sp.getTotalManjianDiscount()).subtract(sp.getTotalManzheDiscount());

        if (redPacketNo != 0) {
            // 判断实付金额是否可以使用红包
            if (totalPrice.compareTo(orderLimit) > 0 || totalPrice.compareTo(orderLimit) == 0) {
                // 去除红包金额
                totalPrice = totalPrice.subtract(redPacketPrice);
            } else {
                rr.setCode(2);
                rr.setMessage("此订单不符合红包或优惠券使用条件，请确认！");
                return rr;
            }
        }
        Integer orderDiscountType = null;// 优惠方式
        if (couponNo != 0 && redPacketNo != 0 && activityStatus == 0) {
            orderDiscountType = 5;
        } else if (couponNo != 0) {
            orderDiscountType = 1;
        } else if (redPacketNo != 0) {
            orderDiscountType = 2;
        } else {
            orderDiscountType = 0;
        }
        if (totalPrice.compareTo(new BigDecimal(0)) < 0) {
            totalPrice = new BigDecimal(0);
        }
        sp.setTotalPrice(totalPrice);
        sp.setRedpacketId(redpacketId);
        sp.setShippingList(shippingList);
        sp.setTotalShipping(totalShipping);
        sp.setVoucherIdList(voucherIdList);
        sp.setRedPacketPrice(redPacketPrice);
        sp.setAllowancePrice(allowancePrice);
        sp.setRedPacketStatus(redPacketStatus);
        sp.setCouponTotalPrice(couponTotalPrice);
        sp.setOrderDiscountType(orderDiscountType);
        sp.setAllShopTotalPrice(allShopTotalPrice);
        sp.setPlusgoodstotal(plusgoodstotal);
        if (selectplusmember.getCode() == 1) {
            sp.setPlususedamount(plusResidualLimit);
        }
        if (judgeStatus != 1) {
            rr.setCode(1);
            rr.setData(sp);
        } else {
            rr.setData(sp);
        }

        return rr;
    }

    @Override
    public ResponseResult createOrders(String para, HttpServletRequest request) throws TransactionException {
        ResponseResult result = null;
        // 获取jedis实例
        Jedis jedis = RedisUtil.getJedis();
        RedisLock redisLock = null;
        try {
            CommonParameterVO cp = JSON.parseObject(para, new TypeReference<CommonParameterVO>() {
            });
            UserInfoVO userInfo = ParseTokenUtils.getUserInfoByToken(cp.getToken());
            redisLock = new RedisLock(jedis, "user-createOrders-" + userInfo.getUserId() + cp.getGoodsIds(), 10000);

            // 用户锁
            if (redisLock.lock()) {
                result = appCreateOrders2(para, request);
                if(result.getCode() != CommonStatusEnum.SUCCESS.getCode()){
                    GlobalTransactionContext.reload(RootContext.getXID()).rollback();
                }
                return result;
            }
            return ResponseResult.fail(BizCodeEnume.OPERATION_FAILED);
        } catch (InterruptedException | TransactionException | ParseException | InvocationTargetException | IllegalAccessException e) {
            e.printStackTrace();
            GlobalTransactionContext.reload(RootContext.getXID()).rollback();
            return ResponseResult.fail(e.getMessage());
        } finally {
            redisLock.unLock();
            jedis.close();
        }


    }

//    @SneakyThrows
//    @GlobalTransactional(rollbackFor = Exception.class)
//    public ResponseResult appCreateOrders(String para, HttpServletRequest request) {
//        ResponseResult rr = new ResponseResult();
//        List<String> orderList = new ArrayList<>();
//        Long orderCancelTime = null;
//        Integer orderCancelMinute = null;
//        Integer goodsPlusDis = 0;
//        try {
//            CommonParameterVO cp = JSON.parseObject(para, new TypeReference<CommonParameterVO>() {
//            });
//            List<StoreInformationVO> storeInformationList = cp.getStoreInformationList();
//            Map<Integer,Integer> goodsFlagMap = new HashMap<>();
//
//            for (StoreInformationVO storeInformation : storeInformationList) {
//                // 获取购物车的店铺id和商品信息
//                List<GoodsInformationVO> goodsList = storeInformation.getGoodsBaseList();
//                for (GoodsInformationVO goodsInformation : goodsList) {
//                    goodsFlagMap.put(goodsInformation.getGoodsId(),goodsInformation.getType());
//                }
//
//            }
//            //超时时间：10秒，
//            long time = System.currentTimeMillis() + 1000*10;
//            List<Integer> goodsIds = cp.getGoodsIds();
//            Integer orderIsShopTake = 2;
//            if(cp != null && cp.getOrderIsShopTake() != null){
//                orderIsShopTake = cp.getOrderIsShopTake();
//            }
//            Integer payMentCode = cp.getPaymentCode();
//            if(null == payMentCode){
//                payMentCode = 1;
//            }
//            String liveId = request.getHeader("liveId");
//            String accountId = request.getHeader("accountId");
//            ObjectMapper mapper = new ObjectMapper();
//            UserInfoVO ui = new UserInfoVO();
//            ui = ParseTokenUtils.getUserInfoByToken(cp.getToken());
//            Integer orderGateShopId = null;
//            String userId = ui.getUserId();
//            String userName = ui.getUserName();
//            String sellerShopId = ui.getShopId();
//            Integer parentShopId = ui.getUserParentShopId();
//            Integer inviteSubsiteId = ui.getInviteSubsiteId();
//            if (parentShopId == null) {
//                parentShopId = 0;
//            }
//            BigDecimal usedamout = new BigDecimal(0);
//            //查询用户是否开通plus会员 并且是否有折扣权益
//            ResponseResult selectplusmember = userServiceClient.queryUserPlusInfo(userId);
//            BigDecimal plusDiscount = null;//plus会员折扣
//            BigDecimal plusResidualLimit = null;//plus会员剩余可用额度
//            if (selectplusmember.getCode() == 1){
//                Map<String,Object> userPlusInfo  = (Map<String,Object>) selectplusmember.getData();
//                plusDiscount = new BigDecimal(userPlusInfo.get("discount").toString());
//                plusResidualLimit = new BigDecimal(userPlusInfo.get("residualLimit").toString());
//                usedamout = plusResidualLimit;//剩余可用额度
//            }
//
//
//            Integer treasureOrderShopId = cp.getTreasureOrderShopId();
//            String orderReceiverName = cp.getOrderReceiverName();// 收货人姓名
//            String orderReceiverAddress = cp.getOrderReceiverAddress();// 收货人地址
//            String orderReceiverContact = cp.getOrderReceiverContact();// 收货人联系方式
//
//            Integer orderReceiverProvinceId = cp.getOrderReceiverProvinceId();// 收货人省Id
//            Integer orderReceiverCityId = cp.getOrderReceiverCityId();// 收货人市Id
//            Integer orderReceiverAreaId = cp.getOrderReceiverAreaId();// 收货人区Id
//            //判断商品是否是虚拟商品
//            if(null != cp.getVirtualGoods() && 0 == cp.getVirtualGoods()){
//                orderReceiverName = ui.getUserName();
//                orderReceiverContact = ui.getUserMobile();
//                orderReceiverAddress = ""; //虚拟订单不需要 收货地址
//                orderReceiverProvinceId = 0;
//                orderReceiverCityId = 0;
//                orderReceiverAreaId = 0;
//            }
//            //判断商品是否是门店商品
//            if(null != cp.getOrderIsShopTake() && 1 == cp.getOrderIsShopTake()){
////            orderReceiverName = ui.getUserName();
////            orderReceiverContact = ui.getUserMobile();
//                orderReceiverAddress = ""; //虚拟订单不需要 收货地址
//                orderReceiverProvinceId = 0;
//                orderReceiverCityId = 0;
//                orderReceiverAreaId = 0;
//            }
//
//            Integer virtualGoods = 1;//0 是虚拟订单 1 不是虚拟订单
//            String  periodOfValidity = null;
//            Integer pastDue = null;
//            // 订单来源
//            Integer orderFromNum = cp.getPlatForm();
//            //查询商品信息 售卖区域 运费信息 参加活动的活动信息等
//            rr = businessServiceClient.queryShipping(para);
//            if (rr.getCode() != CommonStatusEnum.SUCCESS.getCode()) {
//                if (rr.getCode() == BizCodeEnume.PRODUCTS_OUT_OF_STOCK_IN_THIS_SALES_AREA.getCode()) {
//                    //该商品所售区域暂时无货！
//                    return ResponseResult.fail(BizCodeEnume.PRODUCTS_OUT_OF_STOCK_IN_THIS_SALES_AREA.getMsg());
//                } else {
//                    return ResponseResult.fail(BizCodeEnume.NO_INFORMATION_OBTAINED.getMsg());
//                }
//            } else {
//                String goodsDetails = rr.getData().toString();
//                List<WapShopShippingQueryResultVO> wapList = JSON.parseObject(goodsDetails, new TypeReference<List<WapShopShippingQueryResultVO>>() {});
//                // 获取计算价格
//                rr = calculatePrice(para);
//                if (rr.getCode() == 2) {
//                    rr.setCode(2);
//                    rr.setData(null);
//                    return rr;
//                }
//                ShopParaVO detailedPrice = (ShopParaVO) rr.getData();
//                String redpacketId = detailedPrice.getRedpacketId();// 红包编码
//                String platformVoucherCode = detailedPrice.getPlatformVoucherCode();// 平台优惠券code
//                BigDecimal platformVoucherPrice = detailedPrice.getPlatformVoucherPrice();// 平台优惠券金额
//                List<Integer> avaliableGoods = detailedPrice.getAvaliableGoods();// 参与平台优惠券商品id
//                BigDecimal totalPrice = detailedPrice.getTotalPrice();// 获取实付总价
//                List<String> voucherIdList = detailedPrice.getVoucherIdList();// 优惠券id集合
//                BigDecimal redPacketPrice = detailedPrice.getRedPacketPrice();// 获取红包金额
//                Integer orderDiscountType = detailedPrice.getOrderDiscountType();// 优惠方式
//                BigDecimal couponTotalPrice = detailedPrice.getCouponTotalPrice();// 获取总优惠券金额
//                List<ShippingListVO> shippingLists = detailedPrice.getShippingList();
//                BigDecimal manjianDiscountBase = BigDecimal.ZERO;// 获取满减优惠金额
//                BigDecimal manzheDiscountBase = BigDecimal.ZERO;// 获取满折优惠金额
//                List<Map<String, String>> totalGiveawayList = detailedPrice.getGiveawayList(); //获取赠品清单
//                List<Map<String,String>> shopGiveawayList = new ArrayList<Map<String,String>>(); //店铺赠品清单
//                String giveawayInfo = "";//赠品信息
//                Integer redPacketStatus = detailedPrice.getRedPacketStatus();
//                BigDecimal tradeDiscount = BigDecimal.ZERO;
//                Integer totalIntegral = detailedPrice.getTotalIntegral();//积分商品所需积分之和
//                Integer integralGoods = 1; //积分商品 0 是 1否
//
//                //plus商品优惠金额
//                BigDecimal plusgoodsprice = new BigDecimal(0);//plus商品优惠金额
//                BigDecimal plusgoodstotal = new BigDecimal(0);//plus商品优惠总金额
//                //是否为plus订单
//                Integer  plusOrder = 0;
//                // 供应商待发货订单
//                Integer dropShipping = 2;
//                if (null != cp.getIntegralGoods() && cp.getIntegralGoods() == 0) {
//                    integralGoods = 0;
//                    //根据用户id查询用户积分
//                    Integer memberIntegralByUserId = userServiceClient.getMemberIntegralByUserId(userId);
//                    if (null != memberIntegralByUserId && totalIntegral > memberIntegralByUserId) {
//                        rr.setCode(2);
//                        rr.setData(null);
//                        rr.setMessage("你的积分不足" + totalIntegral);
//                        return rr;
//                    }
//                }
//                if (null != couponTotalPrice) {
//                    tradeDiscount = couponTotalPrice.add(redPacketPrice);// 优惠价格
//                }
//                List<Integer> goodsIdList = new ArrayList<Integer>();
//                // 存放ConsumeTrade参数
//                ConsumeTradeParaDTO ctp = new ConsumeTradeParaDTO();
//                // 存放ConsumeRecord参数
//                ConsumeRecordParaDTO crp = new ConsumeRecordParaDTO();
//                // 存放卖家信息
//                ConsumeRecordByBusinessDTO crb = new ConsumeRecordByBusinessDTO();
//
//                BigDecimal orderGoodsAmount = new BigDecimal(0);// 商品总价(不包含运费及优惠金额)
//                BigDecimal orderRptPrice = new BigDecimal(0);// 红包拆分累加金额
//                BigDecimal platformVoucherSplitPrice = BigDecimal.ZERO;// 购物津贴拆分价格
//                BigDecimal redPacketSplitPrice = BigDecimal.ZERO;// 红包
//
//                if (redPacketStatus != null && redPacketStatus == 2) {
//                    rr.setCode(2);
//                    rr.setMessage("红包已使用，请重新选择！");
//                    return rr;
//                }
//                List<OrderCommissionVO> orderCommissionList = new ArrayList<>();
//                // 商户订单号
//                String paymentNumber = "U" + DateUtils.getTimeStamp() + DateUtils.randomLengthByTwo();
//                String orderId = null;// 订单编号
//                String sellerId = null;// 卖家id
//                Integer pinCommonId = null;// 拼团commonid
//                String markId = null;
//                Integer type = null;
//                Integer isMark = null;// 是否是团长
//                Integer groupBookingGoodsId = null;
//                Integer sizeA = null;
//                Integer sizeB = null;
//                Integer sizeC = null;
//
//                for (int i = 0; i < wapList.size(); i++) {
//                    BigDecimal orderSupplyPrice = BigDecimal.ZERO;
//                    Integer supplyShopId = null;
//                    String supplyShopName = null;
//
//
//                    BigDecimal orderGoodsCommission = new BigDecimal(0);//平台佣金
//                    BigDecimal orderBaseCommission =new BigDecimal(0);//平台佣金
//                    BigDecimal goodsMemberDiscount = new BigDecimal(0);//会员折扣
//                    BigDecimal baseMemberDiscount =new BigDecimal(0);//会员折扣
//                    sizeA = wapList.size();
//                    Integer smallOrder = 0;
//                    Integer orderPromotionId = 0;// 是否参加活动值
//                    Integer groupbuyStatus = null;// 拼团状态值
//                    String orderBuyId = null;// markid
//                    Integer goodsQuantity = detailedPrice.getShippingList().get(i).getGoodsQuantity();// 每家店铺商品个数
//
//                    Integer redpacketTType = detailedPrice.getShippingList().get(i).getRedpacketTType();
//                    String itemShopId = detailedPrice.getShippingList().get(i).getItemShopId();// 单品红包所属shopid
//                    String allowanceShopId = detailedPrice.getShippingList().get(i).getAllowanceShopId();// 跨店满减所属shopid
//                    String shopLimit = detailedPrice.getShippingList().get(i).getShopLimit();// 获取店铺红包id
//                    Integer voucherStatus = detailedPrice.getShippingList().get(i).getVoucherStatus();// 优惠券使用状态
//                    Integer shopId = wapList.get(i).getShopId();
//                    if (sellerShopId != null && sellerShopId.toString().equals(shopId.toString())) {
//                        rr.setCode(2);
//                        rr.setMessage("请勿购买自家商品！");
//                        return rr;
//                    }
//
//                    if (voucherStatus != null && voucherStatus == 2) {
//                        rr.setCode(2);
//                        rr.setMessage("优惠券已使用，请重新选择！");
//                        return rr;
//                    }
//
//                    String shopIdByStr = shopId.toString();
//                    BigDecimal orderCptPrice = new BigDecimal(0);// 代金券拆分累加金额
//                    BigDecimal paymentRealPrice = new BigDecimal(0);// goods表实付价格(含运费，去除红包拆分价格)
//                    BigDecimal orderGoodsRptPrice = new BigDecimal(0);// 商品红包拆分累加金额
//                    BigDecimal orderBasePaymentAmount = new BigDecimal(0);// base表实付金额
//                    BigDecimal redPacketSumMoney = new BigDecimal(0);// 记录店铺每次红包拆分金额
//                    BigDecimal platformVoucherShopPrice = new BigDecimal(0);// 平台优惠券店铺拆分
//                    BigDecimal orderGoodsPlatformBear = BigDecimal.ZERO;// 优惠活动中平台承担的金额
//                    BigDecimal orderGoodsAddPlatformBear = BigDecimal.ZERO;
//                    BigDecimal platformVoucherRptPrice = new BigDecimal(0);// 平台优惠券拆分
//                    BigDecimal platformVoucherRptAddPrice = BigDecimal.ZERO;
//
//                    HashMap<Object, Object> hashMap = new HashMap<>();
//                    Integer districtId = wapList.get(i).getDistrictId();// 店铺所在地
//                    // BigDecimal orderPaymentAmount = new BigDecimal(0);//
//                    // goods表实付价格(含运费，去除优惠券拆分价格)
//                    BigDecimal redPacketGoodsSumMoney = new BigDecimal(0);// 记录商品每次红包拆分金额
//                    BigDecimal couponPrice = detailedPrice.getShippingList().get(i).getCouponPrice();// 每家店铺使用优惠券价格
//                    Integer invoiceId = cp.getStoreInformationList().get(i).getInvoiceId();
//                    String invoiceName = null;// 发票信息
//                    //生成订单编号
//                    if (userId.toString().length() <= 8) {
//                        orderId = DateUtils.nowtime() + userId + DateUtils.randomLengthByTwo();// 订单编号
//                    } else {
//                        String oldUserId = userId.toString();
//                        String newUserId = oldUserId.substring(0, 4)
//                                + oldUserId.substring(oldUserId.length() - 4, oldUserId.length());
//                        orderId = DateUtils.nowtime() + newUserId + DateUtils.randomLengthByTwo();// 订单编号
//                    }
//                    //此处增加新开票功能
//                    InvoiceEntityInfoVO invoiceInfo = cp.getStoreInformationList().get(i).getInvoiceInfo();
//                    if(null != invoiceInfo){
//                        invoiceInfo.setOrderId(orderId);
//                        invoiceInfo.setUserId(userId);
//                        invoiceInfo.setInvoiceStatus(1);
//                        orderInvoiceInfoMapper.addInvoiceInfo(invoiceInfo);
//                    }
//
//                    // 红包店铺拆分
//                    if (redpacketId != null && redpacketTType.intValue() == 4) {
//                        // 使用的红包是店铺红包
//                        redPacketSumMoney = redPacketPrice;
//                    } else if (redpacketId != null && (redpacketTType.intValue() == 3 || redpacketTType.intValue() == 5)
//                            && itemShopId.equals(shopIdByStr)) {
//                        // 使用的红包是多品红包
//                        if (i == wapList.size() - 1) {
//                            redPacketSumMoney = redPacketPrice.subtract(redPacketSplitPrice);
//                        } else {
////                      BigDecimal shopPrice = detailedPrice.getShippingList().get(i).getShopPrice();// 单个店铺总价
//                            BigDecimal itemShopPrice = detailedPrice.getShippingList().get(i).getItemShopPrice();// 单个店铺参加活动价格
//                            BigDecimal allredPacketPrice = detailedPrice.getAllredPacketPrice();
//                            redPacketSumMoney = itemShopPrice.divide(allredPacketPrice, 2, BigDecimal.ROUND_HALF_UP)
//                                    .multiply(redPacketPrice).setScale(2, BigDecimal.ROUND_HALF_UP);
//                            redPacketSplitPrice = redPacketSplitPrice.add(redPacketSumMoney);
//                        }
//                    } else {
//                        // redpacketTType.intValue() == 1,2,6
//                        if (redpacketId != null && (redpacketTType.intValue() == 1 || redpacketTType.intValue() == 2
//                                || redpacketTType.intValue() == 6 || redpacketTType.intValue() == 7)) {
//                            // 使用的红包是普通红包
//                            // 红包比例计算拆分
//                            if (i == wapList.size() - 1 && "1".equals(shopLimit)) {
//                                BigDecimal lastRedPacketPrice = redPacketPrice.subtract(orderRptPrice);// 计算最后一家店铺红包金额
//                                redPacketSumMoney = lastRedPacketPrice;
//                                orderRptPrice = lastRedPacketPrice;
//                            } else {
//                                BigDecimal shopPrice = detailedPrice.getShippingList().get(i).getShopPrice();// 单个店铺总价
////                          BigDecimal itemShopPrice = detailedPrice.getShippingList().get(i).getItemShopPrice();// 单个店铺参加活动价格
//                                BigDecimal allShopPrice = detailedPrice.getAllShopTotalPrice();
//                                redPacketSumMoney = shopPrice.divide(allShopPrice, 2, BigDecimal.ROUND_HALF_UP)
//                                        .multiply(redPacketPrice).setScale(2, BigDecimal.ROUND_HALF_UP);
//                                orderRptPrice = orderRptPrice.add(redPacketSumMoney);
//                            }
//                        }
//                    }
//                    // 平台优惠券店铺拆分
//                    if (platformVoucherCode != null && allowanceShopId.equals(shopIdByStr)) {
//                        if (i == wapList.size() - 1) {
//                            platformVoucherShopPrice = platformVoucherPrice.subtract(platformVoucherSplitPrice);// 计算最后一家拆分金额
//                            System.out.println("-----platformVoucherShopPrice-----" + platformVoucherShopPrice);
//                        } else {
////                      BigDecimal shopPrice = detailedPrice.getShippingList().get(i).getShopPrice();// 单个店铺总价
//                            BigDecimal allowanceShopPrice = detailedPrice.getShippingList().get(i).getAllowanceShopPrice();// 店铺参加活动价格
//                            BigDecimal allowancePrice = detailedPrice.getAllowancePrice();
//                            platformVoucherShopPrice = allowanceShopPrice
//                                    .divide(allowancePrice, 2, BigDecimal.ROUND_HALF_UP).multiply(platformVoucherPrice)
//                                    .setScale(2, BigDecimal.ROUND_HALF_UP);
//                            platformVoucherSplitPrice = platformVoucherSplitPrice.add(platformVoucherShopPrice);
//                            System.out.println("-----platformVoucherShopPrice-----" + platformVoucherShopPrice);
//                        }
//                    }
//                    String shopName = wapList.get(i).getShopName();
//                    String buyerMessage = wapList.get(i).getBuyerMessage();
//                    BigDecimal shippingFee = wapList.get(i).getShippingFee();// 店铺运费
//                    String orderGoodsTime = null;
//                    boolean flag = false;
//                    Boolean vkFlag = false;
//                    List<WapShopShippingResultVO> wssrList = wapList.get(i).getGoodsBaseList();
//                    BigDecimal totalDealerCommission = BigDecimal.ZERO;
//                    BigDecimal totalSupplyCommission = BigDecimal.ZERO;
//                    for (int n = 0; n < wssrList.size(); n++) {
//                        // 运费同一模板循环
//                        sizeB = wssrList.size();
//                        List<WapShippingQueryResultVO> wsqrList = wssrList.get(n).getGoodsBaseList();
//                        for (int j = 0; j < wsqrList.size(); j++) {
//                            supplyShopId = wsqrList.get(j).getSupplyShopId();
//                            supplyShopName = wsqrList.get(j).getSupplyShopName();
//                            orderSupplyPrice = orderSupplyPrice.add(wsqrList.get(j).getDealerGoodsPrice().multiply(new BigDecimal(wsqrList.get(j).getGoodsNum())));
//
//                            if (1 == wssrList.size()) {
//                                if (1 == wsqrList.size()) {
//                                    flag = true;
//                                }
//                            }
//                            sizeC = wsqrList.size();
//                            // 商品循环
//                            BigDecimal totalGoodsShippingFee = wsqrList.get(j).getTotalGoodsShippingFee();//商品总邮费
//                            if (totalGoodsShippingFee == null){
//                                totalGoodsShippingFee = BigDecimal.ZERO;
//                            }
//                            Integer commonIsTreasure = wsqrList.get(j).getCommonIsTreasure();// 判断聚宝商品
//                            System.out.println("-----commonIsTreasure-----" + commonIsTreasure);
//                            Integer activityStatus = wsqrList.get(j).getActivityStatus();
//                            ActivityGoodsDetailDTO agd = wsqrList.get(j).getActivityGoodsDetail();
//                            Integer commonType = wsqrList.get(j).getCommonType();
//                            BigDecimal couponSumMoney = new BigDecimal(0);// 记录每次红包拆分金额
//                            Integer commonLimit = wsqrList.get(j).getCommonLimit();// 每人限购 0代表不限购，1 限购
//                            Integer promotionId = 0;
//                            Integer goodsId = null;
//                            Integer commonId = null;
//                            String goodsName = null;
//                            BigDecimal manjianDiscount = BigDecimal.ZERO;// 获取满减优惠金额
//                            BigDecimal manzheDiscount = BigDecimal.ZERO;// 获取满折优惠金额
//                            Integer catId = null;
//                            String goodsSpec = null;
//                            String goodsImage = null;
//                            Integer goodsNum = null;
//                            BigDecimal goodsAmount = new BigDecimal(0);
//                            BigDecimal goodsPrice = new BigDecimal(0);
//                            BigDecimal goodsShippingFee = new BigDecimal(0);
//
//                            if (commonType == 1) {
//                                // 判断活动状态
//                                if (activityStatus == 1) {
//
//                                } else if (activityStatus == 2) {//秒杀
//                                    goodsId = wsqrList.get(j).getGoodsId();// 规格值Id
//                                    goodsIdList.add(goodsId);// 存放goodsId
//                                    commonId = wsqrList.get(j).getCommonId();// commonId
//                                    goodsName = wsqrList.get(j).getGoodsName();// 商品名
//                                    catId = wsqrList.get(j).getCatId();// 上级类目Id
//                                    goodsSpec = wsqrList.get(j).getGoodsSpec();// 规格值
//                                    goodsImage = wsqrList.get(j).getGoodsImage();// 商品图
//                                    goodsNum = wsqrList.get(j).getGoodsNum();// 购买数量
//                                    goodsAmount = new BigDecimal(goodsNum);// 商品数量转换类型
//                                    HashMap<String, Object> map = new HashMap<>();
//                                    map.put("token",cp.getToken());
//                                    map.put("goodsId",wsqrList.get(j).getGoodsId());
//                                    ResponseResult checkLimit = activityServiceClient.seckillCheckLimit(map);
//                                    // 商品价格
//                                    if (checkLimit.getCode() == 1){
//                                        goodsPrice = agd.getActivityPrice();
//                                    }else if (checkLimit.getCode() == 2){
//                                        goodsPrice = wsqrList.get(j).getGoodsPrice();
//                                    }else{
//                                        rr.setCode(3);
//                                        rr.setMessage("token失效，请重新登录");
//                                        return rr;
//                                    }
//                                    goodsShippingFee = wsqrList.get(j).getGoodsShippingFee();// 单件商品运费价格
//                                    orderGoodsAmount = goodsPrice.multiply(goodsAmount);// 付款价格(不含运费)
//                                    groupbuyStatus = 0;
//                                    orderPromotionId = 2;
//                                    promotionId = 2;
//                                } else if (activityStatus == 3) {//限时折扣
//                                    goodsId = wsqrList.get(j).getGoodsId();// 规格值Id
//                                    goodsIdList.add(goodsId);// 存放goodsId
//                                    commonId = wsqrList.get(j).getCommonId();// commonId
//                                    goodsName = wsqrList.get(j).getGoodsName();// 商品名
//                                    catId = wsqrList.get(j).getCatId();// 上级类目Id
//                                    goodsSpec = wsqrList.get(j).getGoodsSpec();// 规格值
//                                    goodsImage = wsqrList.get(j).getGoodsImage();// 商品图
//                                    goodsNum = wsqrList.get(j).getGoodsNum();// 购买数量
//                                    goodsAmount = new BigDecimal(goodsNum);// 商品数量转换类型
//                                    HashMap<String, Object> map = new HashMap<>();
//                                    map.put("token",cp.getToken());
//                                    map.put("goodsId",wsqrList.get(j).getGoodsId());
//                                    ResponseResult checkLimit = activityServiceClient.discountCheckLimit(map);
//                                    // 商品价格
//                                    if (checkLimit.getCode() == 1){
//                                        goodsPrice = agd.getActivityPrice();
//                                    }else if (checkLimit.getCode() == 2){
//                                        goodsPrice = wsqrList.get(j).getGoodsPrice();
//                                    }else{
//                                        rr.setCode(3);
//                                        rr.setMessage("token失效，请重新登录");
//                                        return rr;
//                                    }
//                                    goodsShippingFee = wsqrList.get(j).getGoodsShippingFee();// 单件商品运费价格
//                                    orderGoodsAmount = goodsPrice.multiply(goodsAmount);// 付款价格(不含运费)
//                                    groupbuyStatus = 0;
//                                    orderPromotionId = 3;
//                                    promotionId = 3;
//                                } else if (activityStatus == 4) {//拼团
//                                    goodsId = wsqrList.get(j).getGoodsId();// 规格值Id
//                                    groupBookingGoodsId = goodsId;
//                                    goodsIdList.add(goodsId);// 存放goodsId
//                                    commonId = wsqrList.get(j).getCommonId();// commonId
//                                    pinCommonId = commonId;
//                                    goodsName = wsqrList.get(j).getGoodsName();// 商品名
//                                    catId = wsqrList.get(j).getCatId();// 上级类目Id
//                                    goodsSpec = wsqrList.get(j).getGoodsSpec();// 规格值
//                                    goodsImage = wsqrList.get(j).getGoodsImage();// 商品图
//                                    goodsNum = wsqrList.get(j).getGoodsNum();// 购买数量
//                                    goodsAmount = new BigDecimal(goodsNum);// 商品数量转换类型
//                                    type = agd.getType();
//                                    markId = agd.getMarkId();
//                                    if (type == 1) {
//                                        // 单独购买，不参与拼团
//                                        orderPromotionId = 0;
//                                        groupbuyStatus = 0;
//                                        goodsPrice = agd.getPriceOne();
//                                    } else {
//                                        goodsPrice = agd.getPintuanPrice();// 商品价格
//                                        promotionId = 4;// goods表活动值
//                                        // 参与拼团
//                                        if (markId == null || markId == "") {
//                                            // 判断是否是新开团
//                                            orderBuyId = (DateUtils.timeToStamp()).toString()
//                                                    + DateUtils.randomLengthByTwo();
//                                            markId = orderBuyId;
//                                            isMark = 1;
//                                        } else {
//                                            // 参加已有拼团
//                                            isMark = 2;
//                                            orderBuyId = markId;
//                                        }
//                                        orderPromotionId = 4;
//                                        groupbuyStatus = 1;
//                                    }
//                                    goodsShippingFee = wsqrList.get(j).getGoodsShippingFee();// 单件商品运费价格
//                                    orderGoodsAmount = goodsPrice.multiply(goodsAmount);// 付款价格(不含运费)
//                                } else if (activityStatus == 5) {//满减赠折活动
//                                    goodsId = wsqrList.get(j).getGoodsId();// 规格值Id
//                                    goodsIdList.add(goodsId);// 存放goodsId
//                                    commonId = wsqrList.get(j).getCommonId();// commonId
//                                    goodsName = wsqrList.get(j).getGoodsName();// 商品名
//                                    catId = wsqrList.get(j).getCatId();// 上级类目Id
//                                    goodsSpec = wsqrList.get(j).getGoodsSpec();// 规格值
//                                    goodsImage = wsqrList.get(j).getGoodsImage();// 商品图
//                                    goodsNum = wsqrList.get(j).getGoodsNum();// 购买数量
//                                    goodsAmount = new BigDecimal(goodsNum);// 商品数量转换类型
//                                    goodsPrice = agd.getMjzzPrice();// 商品价格
//                                    goodsShippingFee = wsqrList.get(j).getGoodsShippingFee();// 单件商品运费价格
//                                    orderGoodsAmount = goodsPrice.multiply(goodsAmount);// 付款价格(不含运费)
//                                    groupbuyStatus = 0;
//                                    orderPromotionId = 5;
//                                    promotionId = 5;
//                                    for(ShippingListVO sl :shippingLists){
//                                        if(sl.getShopId().equals(shopId)){
//                                            manjianDiscount = sl.getShopManjianDiscount();// 满减优惠金额
//                                            manzheDiscount = sl.getShopManzheDiscount();// 满折优惠金额
//                                            manjianDiscountBase = manjianDiscountBase.add(manjianDiscount);
//                                            manzheDiscountBase = manzheDiscountBase.add(manzheDiscount);
//                                        }
//                                    }
//
//                                }else {
//                                    goodsId = wsqrList.get(j).getGoodsId();// 规格值Id
//                                    goodsIdList.add(goodsId);// 存放goodsId
//                                    commonId = wsqrList.get(j).getCommonId();// commonId
//                                    goodsName = wsqrList.get(j).getGoodsName();// 商品名
//                                    catId = wsqrList.get(j).getCatId();// 上级类目Id
//                                    goodsSpec = wsqrList.get(j).getGoodsSpec();// 规格值
//                                    goodsImage = wsqrList.get(j).getGoodsImage();// 商品图
//                                    goodsNum = wsqrList.get(j).getGoodsNum();// 购买数量
//                                    goodsAmount = new BigDecimal(goodsNum);// 商品数量转换类型
//                                    goodsPrice = wsqrList.get(j).getGoodsPrice();// 商品价格
//                                    goodsShippingFee = wsqrList.get(j).getGoodsShippingFee();// 单件商品运费价格
//                                    orderGoodsAmount = goodsPrice.multiply(goodsAmount);// 付款价格(不含运费)
//                                    groupbuyStatus = 0;
//                                    orderPromotionId = 0;
//                                }
//                            }
//
//                            if (activityStatus == 2) {//限时秒杀
//                                Integer buyType = goodsFlagMap.get(goodsId);
//                                //若为限时折扣商品且想要用优惠价购买，则需要判断限购条件
//                                if (null != buyType && 0 == buyType) {
//                                    CheckSeckillLimitResultVO data = activityServiceClient.querySeckillInfoByGoodsId(goodsId);
//                                    Integer count = null;
//                                    if (null != data) {
//                                        Integer goodsUpperLimit = data.getGoodsUpperLimit();
//                                        if(null == orderCancelMinute) {
//                                            orderCancelMinute = data.getCancelTime();
//                                        }else if(orderCancelMinute > data.getCancelTime()){
//                                            orderCancelMinute = data.getCancelTime();
//                                        }
//                                        if (0 != goodsUpperLimit) {
//                                            Calendar cal = Calendar.getInstance();
//                                            Map<String, Object> param = new HashMap<>();
//                                            param.put("goodsStartTime",data.getGoodsStartTime());
//                                            param.put("goodsEndTime",data.getGoodsEndTime());
//                                            param.put("goodsId",goodsId);
//                                            param.put("userId",userId);
//                                            param.put("goodsPrice",data.getSeckillPrice());
//                                            count = orderGoodsMapper.queryOrderGoodsCount(param);
//                                            count = count == null ? 0 : count;
//                                            count = count + goodsAmount.intValue();
//                                            if (count > goodsUpperLimit) {
//                                                rr.setCode(2);
//                                                rr.setData(goodsId);
//                                                rr.setMessage("商品:「" + data.getGoodsName() + "」此次活动内只能秒杀下单"+goodsUpperLimit+"件,若需购买请原价购买");
//                                                return rr;
//                                            }
//                                        }
//
//                                    }
//                                }
//                            }
//
//                            if (activityStatus == 3) {//限时折扣
//                                Integer buyType = goodsFlagMap.get(goodsId);
//                                //若为限时折扣商品且想要用优惠价购买，则需要判断限购条件
//                                if (null != buyType && 0 == buyType) {
//                                    CheckDiscountLimitResultVO data = activityServiceClient.queryDiscountInfoByGoodsId(goodsId);
//                                    Integer count = null;
//                                    if (null != data) {
//                                        Integer goodsUpperLimit = data.getGoodsUpperLimit();
//                                        Integer discountUpperTime = data.getDiscountUpperTime();
//                                        if (0 != goodsUpperLimit && 0 != discountUpperTime) {
//                                            Calendar cal = Calendar.getInstance();
//                                            Map<String, Object> param = new HashMap<>();
//                                            Date fdate = new Date();
//                                            cal.setTime(fdate);
//                                            cal.add(Calendar.DATE, -discountUpperTime);
//                                            fdate = cal.getTime();
//                                            param.put("fDate", fdate);
//                                            param.put("goodsId", goodsId);
//                                            param.put("userId", userId);
//                                            param.put("goodsPrice", data.getDiscountPrice());
//                                            count = orderGoodsMapper.queryOrderGoodsCount(param);
//                                            count = count == null ? 0 : count;
//                                            count = count + goodsAmount.intValue();
//                                            if (count > goodsUpperLimit) {
//                                                rr.setCode(2);
//                                                rr.setData(goodsId);
//                                                rr.setMessage("商品:「" + data.getGoodsName() + "」"+discountUpperTime+"天内只能优惠价下单"+goodsUpperLimit+"件,若需购买请原价购买");
//                                                return rr;
//                                            }
//                                        }
//                                    }
//                                }
//                            }
//                            //如果是门店商品 门店用户不能购买自己的商品门店同步是商品
//                            if(null != cp.getOrderIsShopTake() && 1 == cp.getOrderIsShopTake()){
//                                Integer shopTakeStart = orderGoodsMapper.queryShopTakeGoodsStart(wsqrList.get(j).getCommonId(),ui.getShopId());
//                                if(null != shopTakeStart && shopTakeStart > 0){
//                                    rr.setCode(2);
//                                    rr.setMessage("请勿购买自家商品！");
//                                    return rr;
//                                }
//                            }
//
//                            // 判断markid是否为null
//                            if (markId != null && markId.length() != 0) {
//                                ResponseResult resultResp = activityServiceClient.querySurplusNum(markId);
//                                if (resultResp.getCode() == 1) {
//                                    String numberRemaining = (String) resultResp.getData();
//                                    if (Integer.parseInt(numberRemaining) == 0) {
//                                        rr.setCode(2);
//                                        rr.setMessage("当前拼团人数已满，请重新选择！");
//                                        return rr;
//                                    }
//                                }
//                            }
//
//                            Integer orderGoodsStatus = 1;// 订单状态
//                            Integer orderGoodsEvaluationStatus = 0;// 评价状态
//                            Integer goodsReturnStatus = 0;// 退款状态
//                            Integer goodsRefundStatus = 0;// 退货状态
//                            orderGoodsTime = DateUtils.getNowDateToString();// 下单时间
//                            Integer orderGoodsIdDeliver = 0;// 是否发货
//                            BigDecimal goodsRtpPrice = BigDecimal.ZERO;// goods表红包抵扣金额
//                            // 存放商品信息，增加销量
//                            WapGoodsSaleSumUpdateVO wssu = new WapGoodsSaleSumUpdateVO();
//                            Integer goodsType = 0;
//                            List<WapGoodsSaleSumUpdateVO> goodsDetailsList = new ArrayList<WapGoodsSaleSumUpdateVO>();
//
//
//                            List<StoreInformationVO> arrStoreList = cp.getStoreInformationList();
//                            for (StoreInformationVO str1 : arrStoreList) {
//                                List<GoodsInformationVO> goodsList = str1.getGoodsBaseList();
//                                for (GoodsInformationVO str2 : goodsList) {
//                                    // 存放商品信息，增加销量
//                                    wssu = new WapGoodsSaleSumUpdateVO();
//                                    if (null != cp.getOrderIsShopTake() && cp.getOrderIsShopTake() ==1) {
//                                        wssu.setShopGateId(cp.getShopGateId());
//                                    }
//                                    wssu.setToken(cp.getToken());
//                                    wssu.setGoodsId(str2.getGoodsId());
//                                    wssu.setGoodsNum(str2.getGoodsNum());
//                                    wssu.setCommonId(commonId);
//                                    wssu.setGoodsType(goodsType);
//                                    wssu.setTreasureOrderShopId(treasureOrderShopId);
//                                    goodsDetailsList.add(wssu);
//                                }
//                            }
//
//
//                            String str1 = JSON.toJSONString(goodsDetailsList);// list 转 String
//                            RedisUtil.set(YFConfig.YF_SALENUM + orderId, str1, 86400);
//                            RedisUtil.set(YFConfig.YF_SALENUM + paymentNumber, str1, 86400);// 存放库存传值
//
//
//                            if (null != voucherIdList && !voucherIdList.isEmpty()) {
//                                // 红包&优惠券都使用
//                                // 优惠券比例计算拆分
//                                if (flag) {
//                                    BigDecimal shopPrice = detailedPrice.getShippingList().get(i).getShopPrice();// 单个店铺总价
//                                    // 计算最后一件商品优惠券拆分金额
//                                    // 存入最后一个商品的优惠券抵扣金额
//                                    couponSumMoney = couponPrice;// 一件商品不拆分
//                                } else {
//                                    if (sizeA == i + 1 && sizeB == n + 1 && sizeC == j + 1) {
//                                        couponSumMoney = couponPrice.subtract(orderCptPrice);// 计算最后一件商品优惠券拆分金额
//                                    } else {
//                                        BigDecimal shopPrice = detailedPrice.getShippingList().get(i).getShopPrice();// 单个店铺总价
//                                        couponSumMoney = orderGoodsAmount.divide(shopPrice, 2, BigDecimal.ROUND_HALF_UP)
//                                                .multiply(couponPrice).setScale(2, BigDecimal.ROUND_HALF_UP);
//                                        orderCptPrice = orderCptPrice.add(couponSumMoney);// 累加金额
//                                    }
//                                }
//                            }
//                            if(redpacketId != null){
//                                // 判断使用红包类型是否是店铺红包
//                                if (!"1".equals(shopLimit) && shopId.equals(Integer.parseInt(shopLimit))) {
//
//                                } else if ((redpacketTType.intValue() == 3 || redpacketTType.intValue() == 5)
//                                        && itemShopId.equals(shopIdByStr)) {
////                                goodsCatLimit != null && str != -1 && itemShopId.equals(shopIdByStr)
//                                    if (goodsQuantity == 1) {
//                                        // 判断商品个数
//                                        goodsRtpPrice = redPacketSumMoney;
//                                        orderGoodsPlatformBear = redPacketSumMoney;// 优惠活动中平台承担的金额
//                                    } else {
//                                        if (sizeA == i + 1 && sizeB == n + 1 && sizeC == j + 1) {
//                                            goodsRtpPrice = redPacketSumMoney.subtract(orderGoodsRptPrice);
//                                            orderGoodsPlatformBear = redPacketSumMoney.subtract(orderGoodsAddPlatformBear);
//                                        } else {
//                                            BigDecimal itemShopPrice = detailedPrice.getShippingList().get(i)
//                                                    .getItemShopPrice();
//                                            orderGoodsPlatformBear = goodsPrice.multiply(goodsAmount)
//                                                    .divide(itemShopPrice, 2, BigDecimal.ROUND_HALF_UP)
//                                                    .multiply(redPacketSumMoney).setScale(2, BigDecimal.ROUND_HALF_UP);// 拆分比例价格
//                                            orderGoodsAddPlatformBear = orderGoodsAddPlatformBear
//                                                    .add(orderGoodsPlatformBear);// 累加价格
//                                            goodsRtpPrice = orderGoodsPlatformBear;// 赋值红包价格
//                                            orderGoodsRptPrice = orderGoodsRptPrice.add(goodsRtpPrice);// 累加红包拆分价格
//                                        }
//                                    }
//                                } else if (redpacketTType.intValue() == 1 || redpacketTType.intValue() == 2
//                                        || redpacketTType.intValue() == 6 || redpacketTType.intValue() == 7) {
//                                    // 普通红包比例拆分
//                                    if (flag) {
//                                        // 1件商品
//                                        goodsRtpPrice = redPacketSumMoney;
//                                        orderGoodsPlatformBear = redPacketSumMoney;
//                                    } else {
//                                        // 多件商品,判断最后一件
//                                        if (sizeA == i + 1 && sizeB == n + 1 && sizeC == j + 1) {
//                                            goodsRtpPrice = redPacketSumMoney.subtract(orderGoodsRptPrice);
//                                            orderGoodsPlatformBear = redPacketSumMoney.subtract(orderGoodsAddPlatformBear);
//                                        } else {
//                                            BigDecimal shopPrice = detailedPrice.getShippingList().get(i).getShopPrice();// 单个店铺总价
//                                            orderGoodsPlatformBear = orderGoodsAmount
//                                                    .divide(shopPrice, 2, BigDecimal.ROUND_HALF_UP)
//                                                    .multiply(redPacketSumMoney).setScale(2, BigDecimal.ROUND_HALF_UP);// 拆分至每家店铺的红包再次拆分至每一个商品
//                                            goodsRtpPrice = orderGoodsPlatformBear;
//                                            orderGoodsRptPrice = orderGoodsRptPrice.add(goodsRtpPrice);
//                                            orderGoodsAddPlatformBear = orderGoodsAddPlatformBear
//                                                    .add(orderGoodsPlatformBear);
//
//                                        }
//                                    }
//                                }
//                            }
//
//                            // 优惠券&红包都不使用
//                            if(goodsShippingFee == null){
//                                goodsShippingFee = BigDecimal.ZERO;
//                            }
//
//                            if (!CollectionUtils.isEmpty(avaliableGoods) && avaliableGoods.contains(goodsId)) {
//                                if (sizeA == i + 1 && sizeB == n + 1 && sizeC == j + 1) {
//                                    platformVoucherRptPrice = platformVoucherShopPrice.subtract(platformVoucherRptAddPrice);
//                                } else {
//                                    // 购物津贴拆分至goods
////                            BigDecimal shopPrice = detailedPrice.getShippingList().get(i).getShopPrice();// 单个店铺总价
//
//                                    BigDecimal allowanceShopPrice = detailedPrice.getShippingList().get(i)
//                                            .getAllowanceShopPrice();
//                                    platformVoucherRptPrice = goodsPrice.multiply(goodsAmount)
//                                            .divide(allowanceShopPrice, 2, BigDecimal.ROUND_HALF_UP)
//                                            .multiply(platformVoucherShopPrice).setScale(2, BigDecimal.ROUND_HALF_UP);
//                                    platformVoucherRptAddPrice = platformVoucherRptAddPrice.add(platformVoucherRptPrice);
//                                }
//                            }
//
//
//                            BigDecimal price = goodsPrice.multiply(goodsAmount);
//                            BigDecimal plusprice = new BigDecimal(0);//商品减去会员折扣好价格  用于计算plus会员价格
//                            paymentRealPrice = price.add(goodsShippingFee);
//                            BigDecimal orderDiscountFee = new BigDecimal(0);// 总优惠金额
//                            Double gradeDiscount  = 0.0;
//                            //会员折扣
//                            if(null != cp.getMemberClassId() && 0 != cp.getMemberClassId() && activityStatus != 5 ){
//                                ResponseResult resp = baseServiceClient.getMemberNameByClassId(cp.getMemberClassId().toString());
//                                Map<String,Object> map = (Map<String, Object>) resp.getData();
//                                gradeDiscount = (Double) map.get("gradeDiscount");
//                                goodsMemberDiscount = paymentRealPrice.subtract(goodsShippingFee).subtract(((paymentRealPrice.subtract(goodsShippingFee)).multiply(new BigDecimal(gradeDiscount)).setScale(2,BigDecimal.ROUND_HALF_UP)));// 总优惠金额
//                                orderDiscountFee = goodsMemberDiscount.add(orderDiscountFee);
//                                baseMemberDiscount = baseMemberDiscount.add(goodsMemberDiscount);
//
//                                //商品减去会员折扣好价格  用于计算plus会员价格
//                                plusprice = paymentRealPrice.subtract(goodsShippingFee).subtract(goodsMemberDiscount);
//
//                                paymentRealPrice = paymentRealPrice.subtract(goodsMemberDiscount);
//
//                            }
//
//                            //plus会员优惠金额
//                            //查询是否为plus商品
//                            if (selectplusmember.getCode() == 1 && usedamout.compareTo(new BigDecimal(0)) == 1) {
//                                Integer integer = goodServiceClient.queryGoodsIsPlus(wsqrList.get(j).getCommonId());
//                                if (integer == 1) {
//                                    plusOrder = 1;
//                                    BigDecimal data = new BigDecimal(String.valueOf(selectplusmember.getData()));//plus会员折扣
//                                    data = new BigDecimal(1).subtract(data);
//                                    plusgoodsprice = plusprice.multiply(data).setScale(2,BigDecimal.ROUND_HALF_UP);//plus商品  会员折扣金额
//
//                                    //判断可用额度
//                                    if (usedamout.compareTo(new BigDecimal(-1)) != 0){
//                                        if (plusgoodsprice.compareTo(usedamout) == 1){
//                                            plusgoodsprice = usedamout;
//                                        }
//                                        usedamout = usedamout.subtract(plusgoodsprice);
//                                    }
//
//                                    plusgoodstotal = plusgoodstotal.add(plusgoodsprice);//总优惠金额
//                                    paymentRealPrice = paymentRealPrice.subtract(plusgoodsprice).setScale(2,BigDecimal.ROUND_HALF_UP);//支付金额
//                                    baseMemberDiscount = baseMemberDiscount.add(plusgoodsprice);//将plus会员折扣金额加入会员金额
//
//
//
//                                    goodsPlusDis = 1;
//
//                                    //更新plus信息表已用额度
//                                    hashMap.put("userId",userId);
//                                    hashMap.put("usedAmout",plusgoodsprice);
//                                    hashMap.put("totalAmount",plusgoodsprice);
//                                    userServiceClient.updateUserPluslimit(hashMap);
//                                }
//                            }
//
//
//                            paymentRealPrice= paymentRealPrice.subtract(couponSumMoney).subtract(orderGoodsPlatformBear)
//                                    .subtract(platformVoucherRptPrice).setScale(2, BigDecimal.ROUND_HALF_UP);
//
//                            if (paymentRealPrice.compareTo(new BigDecimal(0)) == -1){
//                                paymentRealPrice = new BigDecimal(0);
//                            }
//
//                            BigDecimal catCommission = orderGoodsMapper.queryCatCommission(catId);//查询分类抽佣比例
//                            if(null == catCommission){
//                                catCommission = new BigDecimal(0);
//                            }
//                            //计算 商家抽佣
//                            catCommission = catCommission.divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);//计算平台抽佣
//                            orderGoodsCommission = paymentRealPrice.subtract(goodsShippingFee).multiply(catCommission).setScale(2, BigDecimal.ROUND_HALF_UP);
//                            orderBaseCommission = orderBaseCommission.add(orderGoodsCommission).setScale(2, BigDecimal.ROUND_HALF_UP);
//                            // 供应商待发货订单
//                            if (null != supplyShopId && supplyShopId.intValue() != shopId.intValue()) {
//                                dropShipping = 1;
//                                //因为同步供应商的商品不能加购物车 所以一个订单对应一个商品
//                                //如果是代发货的订单 存放供应商的商品价格 和 商品总价
//                                //根据当前商品查询 供应商 商品信息
//                                Map<String,Object> param = new HashedMap();
//                                param.put("commonId",commonId);
//                                param.put("goodsId",goodsId);
//                                ResponseResult supperGoodsInfo = goodServiceClient.querySupplierGoodsPrice(param);
//                                Map<String,Object> respData  = (Map<String,Object>) supperGoodsInfo.getData();
//                                BigDecimal supperGoodsPrice = new BigDecimal(respData.get("goodsPrice").toString());
//                                supperGoodsPrice = supperGoodsPrice.multiply(new BigDecimal(goodsNum)).setScale(2, BigDecimal.ROUND_HALF_UP);
//                                //计算供应商 抽佣
//                                BigDecimal ordesupperCommission = supperGoodsPrice.multiply(catCommission).setScale(2, BigDecimal.ROUND_HALF_UP);
//
//                                //如果是待发货的订单 查询平台对 经销订单抽佣的经销规则  只针对 经销订单
//                                ResponseResult resp = baseServiceClient.settingDistribute();
//                                Map<String,Object> map = (Map<String, Object>) resp.getData();
//                                if(null != map){
//                                    //自销抽佣开关  1 开 2 关
//                                    Integer value1 = Integer.valueOf(map.get("value1").toString());
//                                    if(2 == value1){
//                                        orderGoodsCommission = new BigDecimal(0);
//                                        orderBaseCommission = new BigDecimal(0);
//                                    }
//                                    //经销抽佣开关 1 开 2 关
//                                    Integer value2 = Integer.valueOf(map.get("value2").toString());
//                                    if(2 == value2){
//                                        ordesupperCommission = new BigDecimal(0);
//                                    }
//                                }
//
//                                respData.put("priceSum",supperGoodsPrice);
//                                respData.put("ordesupperCommission",ordesupperCommission);
//                                respData.put("paymentAmount",supperGoodsPrice.add(goodsShippingFee));
//                                respData.put("goodsNum",goodsNum);
//                                respData.put("orderId",orderId);
//                                System.out.println(respData);
//                                //将供应商订单信息存入数据库
//                                orderBaseMapper.insertSupperOrderBase(respData);
//                            }
//
//                            manjianDiscount = manjianDiscount.setScale(2, BigDecimal.ROUND_HALF_UP);
//                            manzheDiscount = manzheDiscount.setScale(2, BigDecimal.ROUND_HALF_UP);
//                            BigDecimal shopPrice = detailedPrice.getShippingList().get(i).getShopPrice();// 每家店铺商品总价(不包含运费，优惠价格)
//                            orderDiscountFee = orderDiscountFee.add(manjianDiscount).add(manzheDiscount);// 满减活动 + 会员折扣
//                            orderBasePaymentAmount = shopPrice.add(shippingFee).subtract(orderRptPrice).subtract(orderDiscountFee);
//                            paymentRealPrice = paymentRealPrice.subtract(manjianDiscount).subtract(manzheDiscount);
//
//                            if (orderBasePaymentAmount.compareTo(new BigDecimal(0)) == -1){
//                                orderBasePaymentAmount = new BigDecimal(0);
//                            }
//
//                            //判断商品是否是虚拟商品
//                            if( null != cp.getVirtualGoods() &&  0 == cp.getVirtualGoods() ){
//                                Map<String,String> map = new HashMap<>();
//                                map.put("goodsId",String.valueOf(goodsId));
//                                ResponseResult resp = goodServiceClient.queryVirtualgoods(map);
//                                Map<String,Object> respData  = (Map<String,Object>) resp.getData();
//                                virtualGoods = (Integer) respData.get("virtualGoods");
//                                periodOfValidity = (String) respData.get("periodOfValidity");
//                                pastDue = (Integer) respData.get("pastDue");
//                            }
//
//                            // 计算商品经销佣金和供应商佣金
//                            double dealer = wsqrList.get(j).getDealerCommission() == null ? 0 : Double.parseDouble(wsqrList.get(j).getDealerCommission()) / 100;
//                            double supply = wsqrList.get(j).getSupplyCommission() == null ? 0 : Double.parseDouble(wsqrList.get(j).getSupplyCommission()) / 100;
//                            BigDecimal dealerCommission = paymentRealPrice.multiply(new BigDecimal(dealer).setScale(2, BigDecimal.ROUND_HALF_UP));
//                            BigDecimal supplyCommission = paymentRealPrice.multiply(new BigDecimal(supply).setScale(2, BigDecimal.ROUND_HALF_UP));
//                            totalDealerCommission = totalDealerCommission.add(dealerCommission);
//                            totalSupplyCommission = totalSupplyCommission.add(supplyCommission);
//
//                            //查询积分商品所需 的积分
//                            Integer needIntegral = orderBaseMapper.getGoodsIntegral(goodsId);
//                            if( null != needIntegral) {
//                                needIntegral = 0;
//                            }
//
//                            // 创建订单(orderGoods)
//                            boolean isInsertByOrderGoodsSuccess = orderGoodsMapper.insertByOrderGoods(totalGoodsShippingFee,orderId, shopId,
//                                    shopName, goodsId, commonId, userId, goodsName, catId, goodsSpec, goodsPrice, goodsNum,
//                                    goodsImage, goodsShippingFee, orderGoodsAmount, orderGoodsPlatformBear,
//                                    paymentRealPrice, orderGoodsStatus, orderGoodsEvaluationStatus, goodsRtpPrice,
//                                    couponSumMoney, platformVoucherRptPrice, goodsReturnStatus, goodsRefundStatus,
//                                    orderGoodsTime, orderGoodsIdDeliver, promotionId, smallOrder,needIntegral, dealerCommission, supplyCommission,orderGoodsCommission,goodsMemberDiscount,orderDiscountFee,plusgoodsprice,goodsPlusDis);
//
//
//
//                            // 存放goodsnameConsumeTrade
//                            List<String> goodsNameList = new ArrayList<String>();
//                            goodsNameList.add(goodsName);
//                            ctp.setGoodsName(goodsNameList);
//                            // 存放goodsnameConsumeRecord
//                            crp.setGoodsName(goodsNameList);
//                            // 存放卖家商品名
//                            crb.setGoodsName(goodsNameList);
//                            if (isInsertByOrderGoodsSuccess) {
//                                goodsPlusDis = 0;//归0
//                                rr.setCode(1);
//                                rr.setMessage("创建成功！！");
//                            }
//                            Integer fxType = 1;// 1 是通过分享页下单  2 是通过 商城直接下单
//                            //通过推广页购买商品
//                            if (null != cp.getShareUserId() && cp.getShareUserId() != "0"  && null != cp.getShareType()
//                                    && (cp.getShareType().equals(CommonType.goodsShareType.VK_COMMISSION.getCode()) ||  cp.getShareType().equals(CommonType.goodsShareType.VK_INVITE.getCode()) )
//                                    && !userId .equals(cp.getShareUserId())) {
//                                vkFlag = true;
//                                //创建分销佣金订单
//                                OrderCommissionVO orderCommission = fxService.addOrderCommission(wsqrList.get(j), wapList.get(i), ui, cp.getShareUserId(), orderId, paymentRealPrice,fxType);
//                                if (null != orderCommission) {
//                                    orderCommission.setFxTg(1);//分享
//                                    orderCommissionList.add(orderCommission);
//                                }
//                            }else{
//                                fxType = 2;
//                                //微客通过正常页面购买分销商品
//                                //获取微客绑定的上级
//                                Map<String,String> map2 = new HashMap<>(8);
//                                map2.put("userId",ui.getUserId());
//                                ResponseResult resultResp = userServiceClient.queryVKUserInfo(map2);
//                                if(null != resultResp ){//不为null证明是微客否则是普通用户
//                                    VKUserInfoVO shareUserInfo = JSON.parseObject(resultResp.getMessage().toString(),VKUserInfoVO.class);
//                                    if(null != shareUserInfo.getShopUserId() && !(" ".equals(shareUserInfo.getShopUserId()))){
//                                        cp.setShareUserId(shareUserInfo.getShopUserId());
//                                        //创建分销佣金订单
//                                        OrderCommissionVO orderCommission = fxService.addOrderCommission(wsqrList.get(j), wapList.get(i), ui, cp.getShareUserId(), orderId, paymentRealPrice,fxType);
//                                        if (null != orderCommission) {
//                                            orderCommission.setFxTg(2);//推广
//                                            orderCommissionList.add(orderCommission);
//                                        }
//                                    }
//                                }
//                            }
//                        }
//                    }
//
//                    if(null != totalIntegral){
//                        //存放积分商品兑换所需的积分
//                        RedisUtil.set(YFConfig.YF_USERINTEGRALYPAID + "--" + cp.getToken() + "--" + userId,
//                                totalIntegral.toString(), 1200);
//                    }
//                    if ( null == totalPrice ) {
//                        totalPrice = new BigDecimal(0) ;
//                    }
//                    // 存放付款金额
//                    RedisUtil.set(YFConfig.YF_USERAMOUNTACTUALLYPAID + "--" + cp.getToken() + "--" + userId,
//                            totalPrice.toString(), 1200);
//                    String orderDate = DateUtils.getYear() + "-" + DateUtils.getMonth() + "-"
//                            + DateUtils.getDay();
//                    Integer orderBuyerEvaluationStatus = 0;// 买家评价状态
//                    Integer orderStatus = 1;// 订单状态
//                    BigDecimal shopPrice = detailedPrice.getShippingList().get(i).getShopPrice();// 每家店铺商品总价(不包含运费，优惠价格)
//                    BigDecimal orderDiscountFee = new BigDecimal(0);// 总优惠金额
//                    int orderType = CommonType.orderType.GOODS_TYPE.getCode();
//                    orderBasePaymentAmount = shopPrice.add(shippingFee).subtract(platformVoucherShopPrice)
//                            .subtract(redPacketSumMoney).subtract(couponPrice).subtract(manjianDiscountBase).subtract(manzheDiscountBase).subtract(baseMemberDiscount);
//
//                    //使用无门槛红包订单金额小于0
//                    if (orderBasePaymentAmount.compareTo(new BigDecimal(0)) == -1){
//                        orderBasePaymentAmount = new BigDecimal(0);
//                    }
//                    orderDiscountFee = shopPrice.add(shippingFee).subtract(orderBasePaymentAmount).subtract(manjianDiscountBase).subtract(manzheDiscountBase).subtract(baseMemberDiscount);// 总优惠金额
//
//                    ShopUserMessageResultVO shopUserMessageResult = businessServiceClient.queryUserId(shopId);
//                    if (null != shopUserMessageResult || null != cp.getIntegralGoods() && cp.getIntegralGoods() == 0) {
//                        String sellerUserName = null;
//                        String sellerPhone = null;
//                        if(null != cp.getIntegralGoods() && cp.getIntegralGoods() == 0){
//                            sellerUserName = "平台商铺";
//                            sellerId = "1";
//                            sellerPhone = "";
//                        }else{
//                            sellerId = shopUserMessageResult.getUserId();
//                            sellerUserName = shopUserMessageResult.getUserName();
//                            sellerPhone = shopUserMessageResult.getContactsPhone();
//                        }
//                        RedisUtil.set(YFConfig.YF_SELLERPHONE + "--" + orderId, sellerPhone, 86400);
//                        String voucherId = "";
//                        if(null != voucherIdList) {
//                            if (Integer.parseInt(voucherIdList.get(i)) != 0) {
//                                voucherId = voucherIdList.get(i);
//                            }
//                        }
//                        // 创建订单(orderBase)
//                        if (null != cp.getOrderIsShopTake()) {
//                            orderIsShopTake = cp.getOrderIsShopTake();
//                        }
//                        if (null != cp.getShopGateId()) {
//                            orderGateShopId = cp.getShopGateId();
//                        }
//                        String shareUserId = "0";
//                        if (vkFlag) {
//                            shareUserId = null == cp.getShareUserId() ? "0" : cp.getShareUserId();
//                        }
//                        // 供应商待发货订单
//                        if (null != supplyShopId && supplyShopId.intValue() != shopId.intValue()) {
//                            dropShipping = 1;
//                        }
//                        if(payMentCode == 3){
//                            orderStatus = 3;
//                        }
//                        //查询店铺赠品 ZZZ
//                        if(null!=totalGiveawayList) {
//                            for (Map<String, String> giveawayMap : totalGiveawayList) {
//                                if (null != giveawayMap && null != shopId) {
//                                    if (null != giveawayMap.get("shopId") && (shopId.toString()).equals(giveawayMap.get("shopId"))) {
//                                        giveawayMap.remove("shopId");
//                                        shopGiveawayList.add(giveawayMap);
//                                    }
//                                }
//                            }
//                            giveawayInfo = JsonUtils.toString(shopGiveawayList);// list 转 String
//                            shopGiveawayList.clear();
//                        }
//                        boolean isInsertByorderBaseSuccess = orderBaseMapper.insertByOrderBase(orderId, shopId,orderGateShopId ,shopName,
//                                userId, userName, sellerId, sellerUserName, orderDate, orderGoodsTime, orderReceiverName,
//                                orderReceiverAddress, orderReceiverContact, orderReceiverProvinceId, orderReceiverCityId,
//                                orderReceiverAreaId, paymentNumber, invoiceName, invoiceId, shopPrice,
//                                orderBasePaymentAmount, orderDiscountFee, shippingFee, orderBuyerEvaluationStatus,
//                                buyerMessage, orderStatus, orderDiscountType, couponPrice, voucherId, orderFromNum,
//                                redpacketId, redPacketPrice, redPacketSumMoney, platformVoucherCode, platformVoucherPrice,
//                                platformVoucherShopPrice, districtId, parentShopId, inviteSubsiteId, treasureOrderShopId,
//                                orderPromotionId, groupbuyStatus, orderBuyId, smallOrder,liveId,accountId,virtualGoods,periodOfValidity,pastDue,0,
//                                orderType, supplyShopId, supplyShopName, orderSupplyPrice, shareUserId,integralGoods,totalIntegral,orderIsShopTake,dropShipping,
//                                totalDealerCommission, totalSupplyCommission,payMentCode,manjianDiscountBase,manzheDiscountBase,giveawayInfo,orderBaseCommission,baseMemberDiscount,plusOrder);
//                        // consumeRecord所需参数(商家订单)
//                        crb.setSellId(sellerId);
//                        crb.setOrderId(orderId);// 订单号
//                        crb.setUserName(sellerUserName);
//                        crb.setPaymentNumber(paymentNumber);// 支付号
//                        crb.setTotalPrice(orderBasePaymentAmount);
//                        payMentServiceClient.insertConsumeRecordByBusiness(crb);
//                        // fegin调用插入数据ConsumeRecord(买家订单)
//                        crp.setUserId(userId);
//                        crp.setOrderId(orderId);// 订单号
//                        crp.setUserName(userName);
//                        crp.setPaymentNumber(paymentNumber);// 支付号
//                        crp.setTotalPrice(orderBasePaymentAmount);
//                        payMentServiceClient.insertConsumeRecord(crp);
//                        // consumeTrade所需参数
//                        ctp.setUserId(userId);
//                        ctp.setOrderId(orderId);// 订单号
//                        ctp.setSellerId(sellerId);
//                        ctp.setPaymentNumber(paymentNumber);// 支付号
//                        ctp.setTotalPrice(orderBasePaymentAmount);// 商品价格
//                        ctp.setTradeDiscount(tradeDiscount);// 优惠价格
//                        ctp.setTotalIntegral(totalIntegral);//兑换积分商品所需的积分
//                        ctp.setIntegralGoods(integralGoods);
//                        // fegin调用插入数据ConsumeTrade
//                        payMentServiceClient.insertConsumeTrade(ctp);
//                        orderList.add(orderId);
//                        Integer count = orderBaseMapper.checkInvoiceSwitchStatus(shopId);
//                        if(count>0){
//                            if(!orderList.contains(orderId)) {
//                                orderList.add(orderId);
//                            }
//                        }
//                        //更新库存
//                        if (null != cp.getOrderIsShopTake() && cp.getOrderIsShopTake()==1){
//                            String saleSum = RedisUtil.get(YFConfig.YF_SALENUM + orderId);
//                            businessServiceClient.updateShopGateStock(saleSum);
//                        }else{
//                            String saleSum = RedisUtil.get(YFConfig.YF_SALENUM + orderId);
//                            goodServiceClient.updateSaleSum(saleSum);
//                        }
//                        if (isInsertByorderBaseSuccess) {
//
//                            rr.setCode(1);
//                            rr.setMessage("创建成功！");
//                            if (null != orderCancelMinute) {
//                                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//                                Date orderTimeTmp = simpleDateFormat.parse(orderGoodsTime);
//                                Calendar cal = Calendar.getInstance();
//                                cal.setTime(orderTimeTmp);
//                                cal.add(Calendar.MINUTE, orderCancelMinute);
//                                orderTimeTmp = cal.getTime();
//                                orderCancelTime = orderTimeTmp.getTime()/1000;
//                                Date seckillCancelTime = simpleDateFormat.parse(simpleDateFormat.format(orderTimeTmp));
//                                Map<String,Object> map = new HashMap<>();
//                                map.put("orderId",orderId);
//                                map.put("seckillCancelTime",seckillCancelTime);
//                                orderBaseMapper.updateSeckillCancelTime(map);
//                            }
//                        }
//                    }
//                    if(null != cp.getGoodsCat() && cp.getGoodsCat()){
//                        // 下单成功，删除购物车商品
//                        orderUserCartMapper.batchDeleteGoods(userId, goodsIdList);
//                    }
//                }
//                // 批量插入分佣订单
//                if (!CollectionUtils.isEmpty(orderCommissionList)) {
//                    orderCommissionMapper.insertBatch(orderCommissionList);
//                }
//
//                // 更新红包优惠券状态
//                Map<String, Object> statusMap = new HashMap<String, Object>();
//                statusMap.put("redpacketId", redpacketId);
//                statusMap.put("platformVoucherCode", platformVoucherCode);
//                statusMap.put("voucherId", voucherIdList);
//                statusMap.put("type", "1");
//                statusMap.put("orderId", orderId);
//                activityServiceClient.updateSalesPrm(statusMap);
//
//                // 拼团传值
//                JoinPintuanParamVO jpp = new JoinPintuanParamVO();
//                if (type != null && 1 != type) {
//                    jpp.setType(type);
//                    jpp.setToken(cp.getToken());
//                    jpp.setMarkId(markId);
//                    jpp.setUserId(userId);
//                    jpp.setIsMark(isMark);
//                    jpp.setGoodsId(groupBookingGoodsId);
//                    jpp.setCommonId(pinCommonId);
//                    jpp.setOrderId(paymentNumber);
//                    ResponseResult getReturnPara = activityServiceClient.addJoinPintuan(jpp);
//                    Integer code = getReturnPara.getCode();
//                    if (code == 2) {
//                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//                        rr.setCode(2);
//                        rr.setData(null);
//                        rr.setMessage("拼团失败！");
//                        return rr;
//                    } else {
//                        if (RedisUtil.exists(markId)) {
//                            String checkGroupBookingStatusPara = RedisUtil.get(markId);
//                            ExpireMarkIdUpdateParamVO expireMarkIdUpdateParam = JSON.parseObject(checkGroupBookingStatusPara,
//                                    ExpireMarkIdUpdateParamVO.class);
//                            checkGroupBookingStatus(expireMarkIdUpdateParam);
//                        }
//                    }
//                }
//                rr.setCode(1);
//                OrderInfoVO info = new OrderInfoVO();
//                info.setPaymentNumber(paymentNumber);
//                info.setOrderIdList(orderList);
//                info.setOrderCancelTime(orderCancelTime);
//                rr.setData(info);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            // 回滚
//            GlobalTransactionContext.reload(RootContext.getXID()).rollback();
//            return ResponseResult.fail(e.getMessage());
//        }
//        return rr;
//    }


    public ResponseResult appCreateOrders2(String para, HttpServletRequest request) throws TransactionException, ParseException, InvocationTargetException, IllegalAccessException {

        List<String> orderList = new ArrayList<>();
        Long orderCancelTime = null;
        Integer orderCancelMinute = null;
        Integer goodsPlusDis = 0;
        String orderId=null;
        //判断商品是否是 虚拟商品
        Map<String,Object> respData  =new HashMap<>();
        try {
            CommonParameterVO cp = JSON.parseObject(para, new TypeReference<CommonParameterVO>() {
            });
            List<StoreInformationVO> storeInformationList = cp.getStoreInformationList();
            Map<Integer,Integer> goodsFlagMap = new HashMap<>();

            for (StoreInformationVO storeInformation : storeInformationList) {
                // 获取购物车的店铺id和商品信息
                List<GoodsInformationVO> goodsList = storeInformation.getGoodsBaseList();
                for (GoodsInformationVO goodsInformation : goodsList) {
                    goodsFlagMap.put(goodsInformation.getGoodsId(),goodsInformation.getType());
                }

            }
            //超时时间：10秒，
            long time = System.currentTimeMillis() + 1000*10;
            UserInfoVO ui =ParseTokenUtils.getUserInfoByToken(cp.getToken());
            if (ui.getUserParentShopId() == null) {
                ui.setUserParentShopId(0);
            }
            BigDecimal usedamout = new BigDecimal(0);
            //查询用户是否开通plus会员 并且是否有折扣权益
            ResponseResult selectplusmember = userServiceClient.queryUserPlusInfo(ui.getUserId());
            //plus会员折扣
            BigDecimal plusDiscount = null;
            //plus会员剩余可用额度
            BigDecimal plusResidualLimit = null;
            if (selectplusmember.getCode() == 1){
                Map<String,Object> userPlusInfo  = (Map<String,Object>) selectplusmember.getData();
                plusDiscount = new BigDecimal(userPlusInfo.get("discount").toString());
                //剩余可用额度
                plusResidualLimit = new BigDecimal(userPlusInfo.get("residualLimit").toString());
                usedamout = plusResidualLimit;
            }

            /**
             * 订单信息
             */
            CreateOrderDTO dto=getData(ui,cp);
            //查询商品信息 售卖区域 运费信息 参加活动的活动信息等
            ResponseResult rr = businessServiceClient.queryShipping(para);
            if (rr.getCode() != CommonStatusEnum.SUCCESS.getCode()) {
                return rr;
            } else {
                String goodsDetails = rr.getData().toString();
                List<WapShopShippingQueryResultVO> wapList = JSON.parseObject(goodsDetails, new TypeReference<List<WapShopShippingQueryResultVO>>() {});
                // 获取计算价格
                rr = calculatePrice(para);
                if (rr.getCode() == 2) {
                    return rr;
                }
                ShopParaVO detailedPrice = (ShopParaVO) rr.getData();
                //价格信息
                PriceDTO priceDTO=getPriceData(detailedPrice);
                if (null != cp.getIntegralGoods() && cp.getIntegralGoods() == 0) {
                    priceDTO.setIntegralGoods(0);
                    //根据用户id查询用户积分
                    Integer memberIntegralByUserId = userServiceClient.getMemberIntegralByUserId(ui.getUserId());
                    if (null != memberIntegralByUserId && priceDTO.getTotalIntegral() > memberIntegralByUserId) {
                        return ResponseResult.fail(2,"你的积分不足" +  priceDTO.getTotalIntegral());
                    }
                }
                List<Integer> goodsIdList = new ArrayList<>();
                // 存放ConsumeTrade参数
                ConsumeTradeParaDTO ctp = new ConsumeTradeParaDTO();
                // 存放ConsumeRecord参数
                ConsumeRecordParaDTO crp = new ConsumeRecordParaDTO();
                // 存放卖家信息
                ConsumeRecordByBusinessDTO crb = new ConsumeRecordByBusinessDTO();

                if (priceDTO.getRedPacketStatus() != null && priceDTO.getRedPacketStatus() == 2) {
                    //红包已使用，请重新选择！
                    return ResponseResult.fail(BizCodeEnume.RED_ENVELOPE_USED);
                }
                String paymentNumber = "U" + DateUtils.getTimeStamp() + DateUtils.randomLengthByTwo();
                List<OrderCommissionVO> orderCommissionList = new ArrayList<>();
                 Integer sizeA = null;
                 Integer sizeB = null;
                 Integer sizeC = null;
                 //详情信息
                SubclassDTO subclassDTO=new SubclassDTO();
                for (int i = 0; i < wapList.size(); i++) {
                    ShippingListVO shippingListDTO = detailedPrice.getShippingList().get(i);
                    Integer shopId = wapList.get(i).getShopId();
                    sizeA = wapList.size();
                    String shopIdByStr = shopId.toString();
                    if (ui.getShopId() != null && ui.getShopId().equals(shopId.toString())) {
                         //请勿购买自家商品！
                        return ResponseResult.fail(BizCodeEnume.DO_NOT_PURCHASE_YOUR_OWN_PRODUCTS);
                    }
                    StoreInformationVO storeInfoList = cp.getStoreInformationList().get(i);
                    subclassDTO=getSubData(detailedPrice.getShippingList().get(i),storeInfoList,ui,paymentNumber);
                    if (subclassDTO.getVoucherStatus() != null && subclassDTO.getVoucherStatus() == 2) {
                        //优惠券已使用，请重新选择！
                        return ResponseResult.fail(BizCodeEnume.COUPON_USED);
                    }
                    orderId = subclassDTO.getOrderId();
                    HashMap<Object, Object> hashMap = new HashMap<>();
                    // 店铺所在地
                    Integer districtId = wapList.get(i).getDistrictId();
                    //此处增加新开票功能
                    InvoiceEntityInfoVO invoiceInfo = storeInfoList.getInvoiceInfo();
                    if(null != invoiceInfo){
                        invoiceInfo.setOrderId(subclassDTO.getOrderId());
                        invoiceInfo.setUserId(ui.getUserId());
                        invoiceInfo.setInvoiceStatus(1);
                        orderInvoiceInfoMapper.addInvoiceInfo(invoiceInfo);
                    }

                    // 红包店铺拆分
                    if (priceDTO.getRedpacketId() != null && subclassDTO.getRedpacketTType() == 4) {
                        // 使用的红包是店铺红包
                        subclassDTO.setRedPacketSumMoney(priceDTO.getRedPacketPrice());
                    } else if (priceDTO.getRedpacketId() != null && (subclassDTO.getRedpacketTType() == 3 || subclassDTO.getRedpacketTType() == 5)
                            && subclassDTO.getItemShopId().equals(shopIdByStr)) {
                        // 使用的红包是多品红包
                        if (i == wapList.size() - 1) {
                            subclassDTO.setRedPacketSumMoney( priceDTO.getRedPacketPrice().subtract(priceDTO.getRedPacketSplitPrice()));
                        } else {
                            // 单个店铺参加活动价格
                            BigDecimal itemShopPrice = detailedPrice.getShippingList().get(i).getItemShopPrice();
                            BigDecimal allredPacketPrice = detailedPrice.getAllredPacketPrice();
                            subclassDTO.setRedPacketSumMoney(itemShopPrice.divide(allredPacketPrice, 2, RoundingMode.HALF_UP)
                                    .multiply(priceDTO.getRedPacketPrice()).setScale(2, RoundingMode.HALF_UP));
                            priceDTO.setRedPacketSplitPrice(priceDTO.getRedPacketSplitPrice().add(subclassDTO.getRedPacketSumMoney()));
                        }
                    } else {
                        if (priceDTO.getRedpacketId() != null && (subclassDTO.getRedpacketTType() == 1 || subclassDTO.getRedpacketTType() == 2
                                || subclassDTO.getRedpacketTType() == 6 || subclassDTO.getRedpacketTType() == 7)) {
                            // 使用的红包是普通红包
                            // 红包比例计算拆分
                            if (i == wapList.size() - 1 && "1".equals(subclassDTO.getShopLimit())) {
                                BigDecimal lastRedPacketPrice = priceDTO.getRedPacketPrice().subtract(priceDTO.getOrderRptPrice());// 计算最后一家店铺红包金额
                                subclassDTO.setRedPacketSumMoney(lastRedPacketPrice);
                                priceDTO.setOrderRptPrice(lastRedPacketPrice);
                            } else {
                                BigDecimal shopPrice = detailedPrice.getShippingList().get(i).getShopPrice();// 单个店铺总价
//                          BigDecimal itemShopPrice = detailedPrice.getShippingList().get(i).getItemShopPrice();// 单个店铺参加活动价格
                                BigDecimal allShopPrice = detailedPrice.getAllShopTotalPrice();
                                subclassDTO.setRedPacketSumMoney(shopPrice.divide(allShopPrice, 2, RoundingMode.HALF_UP)
                                        .multiply(priceDTO.getRedPacketPrice()).setScale(2, RoundingMode.HALF_UP));
                                priceDTO.setOrderRptPrice(priceDTO.getOrderRptPrice().add(subclassDTO.getRedPacketSumMoney()));
                            }
                        }
                    }
                    // 平台优惠券店铺拆分
                    if (priceDTO.getPlatformVoucherCode() != null && subclassDTO.getAllowanceShopId().equals(shopIdByStr)) {
                        if (i == wapList.size() - 1) {
                            // 计算最后一家拆分金额
                            subclassDTO.setPlatformVoucherShopPrice(priceDTO.getPlatformVoucherPrice().subtract(priceDTO.getPlatformVoucherSplitPrice()));
                        } else {
                            // 店铺参加活动价格
                            BigDecimal allowanceShopPrice = detailedPrice.getShippingList().get(i).getAllowanceShopPrice();
                            BigDecimal allowancePrice = detailedPrice.getAllowancePrice();
                            subclassDTO.setPlatformVoucherShopPrice (allowanceShopPrice
                                    .divide(allowancePrice, 2, RoundingMode.HALF_UP).multiply(priceDTO.getPlatformVoucherPrice())
                                    .setScale(2, RoundingMode.HALF_UP));
                            priceDTO.setPlatformVoucherSplitPrice(priceDTO.getPlatformVoucherSplitPrice().add(subclassDTO.getPlatformVoucherShopPrice()));
                        }
                    }
                    String shopName = wapList.get(i).getShopName();
                    String buyerMessage = wapList.get(i).getBuyerMessage();
                    BigDecimal shippingFee = wapList.get(i).getShippingFee();// 店铺运费
                    String orderGoodsTime = null;
                    boolean flag = false;
                    Boolean vkFlag = false;
                    List<WapShopShippingResultVO> wssrList = wapList.get(i).getGoodsBaseList();
                    BigDecimal totalDealerCommission = BigDecimal.ZERO;
                    BigDecimal totalSupplyCommission = BigDecimal.ZERO;
                    List<String> voucherNoList = new ArrayList<>();
                    if(priceDTO.getVoucherIdList() != null) {
                        voucherNoList = Arrays.asList(priceDTO.getVoucherIdList().get(i).split("-"));
                    }
                    List<String> voucherIdList = new ArrayList<>(voucherNoList);
                    for (int n = 0; n < wssrList.size(); n++) {
                        // 运费同一模板循环
                        sizeB = wssrList.size();
                        List<WapShippingQueryResultVO> wsqrList = wssrList.get(n).getGoodsBaseList();
                        for (int j = 0; j < wsqrList.size(); j++) {
                            subclassDTO.setSupplyShopId(wsqrList.get(j).getSupplyShopId());
                            subclassDTO.setSupplyShopName(wsqrList.get(j).getSupplyShopName());
                            subclassDTO.setOrderSupplyPrice(subclassDTO.getOrderSupplyPrice().add(wsqrList.get(j).getDealerGoodsPrice().multiply(new BigDecimal(wsqrList.get(j).getGoodsNum()))));
                            if (1 == wssrList.size()) {
                                if (1 == wsqrList.size()) {
                                    flag = true;
                                }
                            }
                            sizeC = wsqrList.size();
                            // 商品循环
                            //商品总邮费
                            BigDecimal totalGoodsShippingFee = wsqrList.get(j).getTotalGoodsShippingFee();
                            if (totalGoodsShippingFee == null){
                                totalGoodsShippingFee = BigDecimal.ZERO;
                            }
                            // 判断聚宝商品
                            Integer commonIsTreasure = wsqrList.get(j).getCommonIsTreasure();
                            System.out.println("-----commonIsTreasure-----" + commonIsTreasure);
                            Integer activityStatus = wsqrList.get(j).getActivityStatus();
                            ActivityGoodsDetailDTO agd = wsqrList.get(j).getActivityGoodsDetail();
                            Integer commonType = wsqrList.get(j).getCommonType();
                            // 记录每次红包拆分金额
                            BigDecimal couponSumMoney = new BigDecimal(0);
                            // 每人限购 0代表不限购，1 限购
                            Integer commonLimit = wsqrList.get(j).getCommonLimit();
                            Integer promotionId = 0;//活动类型 0 普通点单 1 砍价（废弃） 2 秒杀 3 限时折扣 4拼团 5 满减赠 6 满减折
                            Integer goodsPromotionId = 0;//活动id
                            Integer goodsId = null;
                            Integer commonId = null;
                            String goodsName = null;
                            BigDecimal manjianDiscount = BigDecimal.ZERO;// 获取满减优惠金额
                            BigDecimal manzheDiscount = BigDecimal.ZERO;// 获取满折优惠金额
                            Integer catId = null;
                            String goodsSpec = null;
                            String goodsImage = null;
                            Integer goodsNum = null;
                            BigDecimal goodsAmount = new BigDecimal(0);
                            BigDecimal goodsPrice = new BigDecimal(0);
                            BigDecimal goodsShippingFee = new BigDecimal(0);
                            BigDecimal activityUnitPrice = BigDecimal.ZERO;
                            if (commonType == 1) {
                                // 判断活动状态
                                if (activityStatus == 1) {

                                } else if (activityStatus == 2) {//秒杀
                                    goodsId = wsqrList.get(j).getGoodsId();// 规格值Id
                                    goodsIdList.add(goodsId);// 存放goodsId
                                    commonId = wsqrList.get(j).getCommonId();// commonId
                                    goodsName = wsqrList.get(j).getGoodsName();// 商品名
                                    catId = wsqrList.get(j).getCatId();// 上级类目Id
                                    goodsSpec = wsqrList.get(j).getGoodsSpec();// 规格值
                                    goodsImage = wsqrList.get(j).getGoodsImage();// 商品图
                                    goodsNum = wsqrList.get(j).getGoodsNum();// 购买数量
                                    goodsAmount = new BigDecimal(goodsNum);// 商品数量转换类型
                                    HashMap<String, Object> map = new HashMap<>();
                                    map.put("token",cp.getToken());
                                    map.put("goodsId",wsqrList.get(j).getGoodsId());
                                    ResponseResult checkLimit = activityServiceClient.seckillCheckLimit(map);
                                    // 商品价格
                                    if (checkLimit.getCode() == 1){
                                        goodsPrice = agd.getActivityPrice();
                                    }else if (checkLimit.getCode() == 2){
                                        goodsPrice = wsqrList.get(j).getGoodsPrice();
                                    }else{
                                        return ResponseResult.fail(BizCodeEnume.TOKEN_IS_INVALID);
                                    }
                                    activityUnitPrice = goodsPrice;
                                    // 单件商品运费价格
                                    goodsShippingFee = wsqrList.get(j).getGoodsShippingFee();
                                    // 付款价格(不含运费)
                                    priceDTO.setOrderGoodsAmount( goodsPrice.multiply(goodsAmount));
                                    subclassDTO.setGroupbuyStatus(0);
                                    subclassDTO.setOrderPromotionId(2);
                                    promotionId = 2;
                                    if(null != agd.getActivityStartStatus() && agd.getActivityStartStatus() == 1){
                                        goodsPromotionId = agd.getSeckillGoods().getSeckillId();
                                    }
                                } else if (activityStatus == 3) {//限时折扣
                                    goodsId = wsqrList.get(j).getGoodsId();// 规格值Id
                                    goodsIdList.add(goodsId);// 存放goodsId
                                    commonId = wsqrList.get(j).getCommonId();// commonId
                                    goodsName = wsqrList.get(j).getGoodsName();// 商品名
                                    catId = wsqrList.get(j).getCatId();// 上级类目Id
                                    goodsSpec = wsqrList.get(j).getGoodsSpec();// 规格值
                                    goodsImage = wsqrList.get(j).getGoodsImage();// 商品图
                                    goodsNum = wsqrList.get(j).getGoodsNum();// 购买数量
                                    goodsAmount = new BigDecimal(goodsNum);// 商品数量转换类型
                                    HashMap<String, Object> map = new HashMap<>();
                                    map.put("token",cp.getToken());
                                    map.put("goodsId",wsqrList.get(j).getGoodsId());
                                    ResponseResult checkLimit = activityServiceClient.discountCheckLimit(map);
                                    // 商品价格
                                    if (checkLimit.getCode() == 1){
                                        goodsPrice = agd.getActivityPrice();
                                    }else if (checkLimit.getCode() == 2){
                                        goodsPrice = wsqrList.get(j).getGoodsPrice();
                                    }else{
                                        return ResponseResult.fail(BizCodeEnume.TOKEN_IS_INVALID);
                                    }
                                    activityUnitPrice = goodsPrice;
                                    // 单件商品运费价格
                                    goodsShippingFee = wsqrList.get(j).getGoodsShippingFee();
                                    // 付款价格(不含运费)
                                    priceDTO.setOrderGoodsAmount( goodsPrice.multiply(goodsAmount));
                                    subclassDTO.setGroupbuyStatus(0);
                                    subclassDTO.setOrderPromotionId(3);
                                    promotionId = 3;
                                    if(null != agd.getActivityStartStatus() && agd.getActivityStartStatus() == 1){
                                        goodsPromotionId = agd.getDiscountGoods().getDiscountId();
                                    }
                                } else if (activityStatus == 4 && cp.getPlatForm() != null && cp.getPlatForm() != 1) {//拼团
                                    goodsId = wsqrList.get(j).getGoodsId();// 规格值Id
                                    subclassDTO.setGroupBookingGoodsId(goodsId);

                                    goodsIdList.add(goodsId);// 存放goodsId
                                    commonId = wsqrList.get(j).getCommonId();// commonId
                                    subclassDTO.setPinCommonId(commonId);
                                    goodsName = wsqrList.get(j).getGoodsName();// 商品名
                                    catId = wsqrList.get(j).getCatId();// 上级类目Id
                                    goodsSpec = wsqrList.get(j).getGoodsSpec();// 规格值
                                    goodsImage = wsqrList.get(j).getGoodsImage();// 商品图
                                    goodsNum = wsqrList.get(j).getGoodsNum();// 购买数量
                                    goodsAmount = new BigDecimal(goodsNum);// 商品数量转换类型
                                    subclassDTO.setType(agd.getType());
                                    subclassDTO.setMarkId(agd.getMarkId());
                                    if (subclassDTO.getType() == 1) {
                                        // 单独购买，不参与拼团
                                        subclassDTO.setGroupbuyStatus(0);
                                        subclassDTO.setOrderPromotionId(0);
                                        goodsPrice = agd.getPriceOne();
                                    } else {
                                        goodsPrice = agd.getPintuanPrice();// 商品价格
                                        promotionId = 4;// goods表活动值
                                        // 参与拼团
                                        if (subclassDTO.getMarkId() == null || subclassDTO.getMarkId().isEmpty()) {
                                            // 判断是否是新开团
                                            subclassDTO.setOrderBuyId((DateUtils.timeToStamp()).toString()
                                                    + DateUtils.randomLengthByTwo());
                                            subclassDTO.setMarkId(subclassDTO.getOrderBuyId());
                                            subclassDTO.setIsMark(1);
                                        } else {
                                            // 参加已有拼团
                                            subclassDTO.setIsMark(2);
                                            subclassDTO.setOrderBuyId(subclassDTO.getMarkId());
                                        }
                                        subclassDTO.setGroupbuyStatus(1);
                                        subclassDTO.setOrderPromotionId(4);
                                    }
                                    activityUnitPrice = goodsPrice;
                                    goodsShippingFee = wsqrList.get(j).getGoodsShippingFee();// 单件商品运费价格
                                    priceDTO.setOrderGoodsAmount(goodsPrice.multiply(goodsAmount));// 付款价格(不含运费)
                                } else if (activityStatus == 5) {//满减赠折活动
                                    goodsId = wsqrList.get(j).getGoodsId();// 规格值Id
                                    goodsIdList.add(goodsId);// 存放goodsId
                                    commonId = wsqrList.get(j).getCommonId();// commonId
                                    goodsName = wsqrList.get(j).getGoodsName();// 商品名
                                    catId = wsqrList.get(j).getCatId();// 上级类目Id
                                    goodsSpec = wsqrList.get(j).getGoodsSpec();// 规格值
                                    goodsImage = wsqrList.get(j).getGoodsImage();// 商品图
                                    goodsNum = wsqrList.get(j).getGoodsNum();// 购买数量
                                    goodsAmount = new BigDecimal(goodsNum);// 商品数量转换类型
                                    goodsPrice = wsqrList.get(j).getGoodsPrice();;// 商品价格
                                    goodsShippingFee = wsqrList.get(j).getGoodsShippingFee();// 单件商品运费价格
                                    // 付款价格(不含运费)
                                    priceDTO.setOrderGoodsAmount(goodsPrice.multiply(goodsAmount));
                                    subclassDTO.setGroupbuyStatus(0);
                                    subclassDTO.setOrderPromotionId(5);
                                    promotionId = 5;
                                    for(ShippingListVO sl :priceDTO.getShippingLists()){
                                        if(sl.getShopId().equals(shopId)){
                                            manjianDiscount = sl.getShopManjianDiscount();// 满减优惠金额
                                            manzheDiscount = sl.getShopManzheDiscount();// 满折优惠金额
                                            priceDTO.setManjianDiscountBase(priceDTO.getManzheDiscountBase().add(manjianDiscount));
                                            priceDTO.setManzheDiscountBase(priceDTO.getManzheDiscountBase().add(manzheDiscount));
                                        }
                                    }

                                }else {
                                    goodsId = wsqrList.get(j).getGoodsId();// 规格值Id
                                    goodsIdList.add(goodsId);// 存放goodsId
                                    commonId = wsqrList.get(j).getCommonId();// commonId
                                    goodsName = wsqrList.get(j).getGoodsName();// 商品名
                                    catId = wsqrList.get(j).getCatId();// 上级类目Id
                                    goodsSpec = wsqrList.get(j).getGoodsSpec();// 规格值
                                    goodsImage = wsqrList.get(j).getGoodsImage();// 商品图
                                    goodsNum = wsqrList.get(j).getGoodsNum();// 购买数量
                                    goodsAmount = new BigDecimal(goodsNum);// 商品数量转换类型
                                    goodsPrice = wsqrList.get(j).getGoodsPrice();// 商品价格
                                    goodsShippingFee = wsqrList.get(j).getGoodsShippingFee();// 单件商品运费价格
                                    // 付款价格(不含运费)
                                    priceDTO.setOrderGoodsAmount(goodsPrice.multiply(goodsAmount));
                                    subclassDTO.setGroupbuyStatus(0);
                                    subclassDTO.setOrderPromotionId(0);
                                }
                            }
                            //查询积分商品所需 的积分
                            Integer isLimit = orderBaseMapper.getIntegralGoodsIsLimit(goodsId);
                            if(cp.getIntegralGoods() != null && null != isLimit && isLimit > 0) {
                                Integer buyCount = orderGoodsMapper.queryBuyCountByGoodsId(goodsId, ui.getUserId());
                                buyCount = buyCount == null ? 0 : buyCount;
                                if(buyCount + goodsNum > isLimit){
                                    return ResponseResult.fail(BizCodeEnume.GOODS_EXCEEDS_THE_MAXIMUM_PURCHASE_LIMIT);
                                }
                            }
                            if (activityStatus == 2) {//限时秒杀
                                Integer buyType = goodsFlagMap.get(goodsId);
                                //若为限时折扣商品且想要用优惠价购买，则需要判断限购条件
                                if (null != buyType && 0 == buyType) {
                                    CheckSeckillLimitResultVO data = activityServiceClient.querySeckillInfoByGoodsId(goodsId);
                                    Integer count = null;
                                    if (null != data) {
                                        Integer goodsUpperLimit = data.getGoodsUpperLimit();
                                        if(null == orderCancelMinute) {
                                            orderCancelMinute = data.getCancelTime();
                                        }else if(orderCancelMinute > data.getCancelTime()){
                                            orderCancelMinute = data.getCancelTime();
                                        }
                                        if (0 != goodsUpperLimit) {
                                            Map<String, Object> param = new HashMap<>();
                                            param.put("goodsStartTime",data.getGoodsStartTime());
                                            param.put("goodsEndTime",data.getGoodsEndTime());
                                            param.put("goodsId",goodsId);
                                            param.put("commonId", commonId);
                                            param.put("seckillId", data.getSeckillId());
                                            param.put("userId",ui.getUserId());
                                            count = orderGoodsMapper.queryOrderGoodsCount(param);
                                            count = count == null ? 0 : count;
                                            count = count + goodsAmount.intValue();
                                            if (count > goodsUpperLimit) {
                                                return ResponseResult.fail(0,"商品:「" + data.getGoodsName() + "」此次活动内只能秒杀下单"+goodsUpperLimit+"件");
                                            }
                                        }

                                    }
                                }
                            }

                            if (activityStatus == 3) {//限时折扣
                                Integer buyType = goodsFlagMap.get(goodsId);
                                //若为限时折扣商品且想要用优惠价购买，则需要判断限购条件
                                if (null != buyType && 0 == buyType) {
                                    CheckDiscountLimitResultVO data = activityServiceClient.queryDiscountInfoByGoodsId(goodsId);
                                    Integer count = null;
                                    if (null != data) {
                                        Integer goodsUpperLimit = data.getGoodsUpperLimit();
                                        Integer discountUpperTime = data.getDiscountUpperTime();
                                        if (0 != goodsUpperLimit && 0 != discountUpperTime) {
                                            Calendar cal = Calendar.getInstance();
                                            Map<String, Object> param = new HashMap<>();
                                            Date fdate = new Date();
                                            cal.setTime(fdate);
                                            cal.add(Calendar.DATE, -discountUpperTime);
                                            fdate = cal.getTime();
                                            param.put("fDate", fdate);
                                            param.put("goodsId", goodsId);
                                            param.put("commonId", commonId);
                                            param.put("discountId", data.getDiscountId());
                                            param.put("userId", ui.getUserId());
                                            count = orderGoodsMapper.queryOrderGoodsCountByDiscount(param);
                                            count = count == null ? 0 : count;
                                            count = count + goodsAmount.intValue();
                                            if (count > goodsUpperLimit) {
                                                return ResponseResult.fail(0,"商品:「" + data.getGoodsName() + "」"+discountUpperTime+"天内只能优惠价下单"+goodsUpperLimit+"件");
                                            }
                                        }
                                    }
                                }
                            }
                            //如果是门店商品 门店用户不能购买自己的商品门店同步是商品
                            if(null != cp.getOrderIsShopTake() && 1 == cp.getOrderIsShopTake()){
                                Integer shopTakeStart = orderGoodsMapper.queryShopTakeGoodsStart(wsqrList.get(j).getCommonId(),ui.getShopId());
                                if(null != shopTakeStart && shopTakeStart > 0){
                                    return ResponseResult.fail(BizCodeEnume.DO_NOT_PURCHASE_YOUR_OWN_PRODUCTS);
                                }
                            }

                            // 判断markid是否为null
                            if (agd.getMarkId() != null && subclassDTO.getMarkId() != null && !subclassDTO.getMarkId().isEmpty()) {
                                ResponseResult resultResp = activityServiceClient.querySurplusNum(subclassDTO.getMarkId());
                                if (resultResp.getCode() == 1) {
                                    Integer numberRemaining = (Integer) resultResp.getData();
                                    if (numberRemaining == 0) {
                                        return ResponseResult.fail(0, "当前拼团人数已满，请重新选择！");
                                    }
                                }
                            }

                            Integer orderGoodsStatus = 1;// 订单状态
                            Integer orderGoodsEvaluationStatus = 0;// 评价状态
                            Integer goodsReturnStatus = 0;// 退款状态
                            Integer goodsRefundStatus = 0;// 退货状态
                            orderGoodsTime = DateUtils.getNowDateToString();// 下单时间
                            Integer orderGoodsIdDeliver = 0;// 是否发货
                            BigDecimal goodsRtpPrice = BigDecimal.ZERO;// goods表红包抵扣金额
                            // 存放商品信息，增加销量
                            WapGoodsSaleSumUpdateVO wssu = new WapGoodsSaleSumUpdateVO();
                            Integer goodsType = 0;
                            List<WapGoodsSaleSumUpdateVO> goodsDetailsList = new ArrayList<WapGoodsSaleSumUpdateVO>();


                            List<StoreInformationVO> arrStoreList = cp.getStoreInformationList();
                            for (StoreInformationVO str1 : arrStoreList) {
                                List<GoodsInformationVO> goodsList = str1.getGoodsBaseList();
                                for (GoodsInformationVO str2 : goodsList) {
                                    // 存放商品信息，增加销量
                                    wssu = new WapGoodsSaleSumUpdateVO();
                                    if (null != cp.getOrderIsShopTake() && cp.getOrderIsShopTake() ==1) {
                                        wssu.setShopGateId(cp.getShopGateId());
                                    }
                                    wssu.setToken(cp.getToken());
                                    wssu.setGoodsId(str2.getGoodsId());
                                    wssu.setGoodsNum(str2.getGoodsNum());
                                    wssu.setCommonId(commonId);
                                    wssu.setGoodsType(goodsType);
                                    wssu.setTreasureOrderShopId(dto.getTreasureOrderShopId());
                                    goodsDetailsList.add(wssu);
                                }
                            }


                            String str1 = JSON.toJSONString(goodsDetailsList);// list 转 String
                            RedisUtil.set(YFConfig.YF_SALENUM + subclassDTO.getOrderId(), str1, 86400);
                            RedisUtil.set(YFConfig.YF_SALENUM + subclassDTO.getPaymentNumber(), str1, 86400);// 存放库存传值

                            Integer voucherId = 0;
                            if (null != priceDTO.getVoucherIdList() && ! priceDTO.getVoucherIdList().isEmpty()) {
                                // 红包&优惠券都使用
                                // 优惠券比例计算拆分
                                if (flag) {
                                    BigDecimal shopPrice = detailedPrice.getShippingList().get(i).getShopPrice();// 单个店铺总价
                                    // 计算最后一件商品优惠券拆分金额
                                    // 存入最后一个商品的优惠券抵扣金额
                                    // 一件商品不拆分
                                    couponSumMoney = subclassDTO.getCouponPrice();
                                } else {
                                    // 获取代金券Id,并封装Map,在向malls请求数据
                                    Map<String, Object> couponIdMap = new HashMap<>();
                                    if(voucherNoList.size() > 1){
                                        for (String couponId : voucherIdList) {
                                            couponIdMap.put("voucherId", couponId);
                                            // 创建接收bean
                                            VoucherBaseVO voucher = activityServiceClient.getVoucherDetail(couponIdMap);
                                            if(voucher.getAvaliableGoods().contains(goodsId) &&
                                                    BigDecimal.valueOf(voucher.getVoucherLimit()).compareTo(priceDTO.getOrderGoodsAmount()) <= 0){
                                                // 获取优惠券价格
                                                couponSumMoney = BigDecimal.valueOf(voucher.getVoucherPrice());
                                                voucherId = voucher.getVoucherId();
                                                voucherIdList.remove(voucher.getVoucherId().toString());
                                                break;
                                            }
                                        }
                                    }else if(voucherNoList.size() == 1){
                                        if(!voucherNoList.get(0).equals("0")) {
                                            couponIdMap.put("voucherId", voucherNoList.get(0));
                                            VoucherBaseVO voucher = activityServiceClient.getVoucherDetail(couponIdMap);
                                            if (voucher.getIsShopVoucher() == 2) {
                                                if (voucher.getAvaliableGoods().contains(goodsId) &&
                                                        BigDecimal.valueOf(voucher.getVoucherLimit()).compareTo(priceDTO.getOrderGoodsAmount()) <= 0) {
                                                    // 获取优惠券价格
                                                    couponSumMoney = BigDecimal.valueOf(voucher.getVoucherPrice());
                                                    voucherId = voucher.getVoucherId();
                                                }
                                            } else {
                                                if (sizeA == i + 1 && sizeB == n + 1 && sizeC == j + 1) {
                                                    // 计算最后一件商品优惠券拆分金额
                                                    couponSumMoney = subclassDTO.getCouponPrice().subtract(subclassDTO.getOrderCptPrice());
                                                } else {
                                                    // 单个店铺总价
                                                    BigDecimal shopPrice = detailedPrice.getShippingList().get(i).getShopPrice();
                                                    couponSumMoney = priceDTO.getOrderGoodsAmount().divide(shopPrice, 2, RoundingMode.HALF_UP)
                                                            .multiply(subclassDTO.getCouponPrice()).setScale(2, RoundingMode.HALF_UP);
                                                    // 累加金额
                                                    subclassDTO.setOrderCptPrice(subclassDTO.getOrderCptPrice().add(couponSumMoney));
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            if(priceDTO.getRedpacketId() != null){
                                // 判断使用红包类型是否是店铺红包
                                if (!"1".equals(subclassDTO.getShopLimit()) && shopId.equals(Integer.parseInt(subclassDTO.getShopLimit()))) {

                                } else if ((subclassDTO.getRedpacketTType() == 3 || subclassDTO.getRedpacketTType() == 5)
                                        && subclassDTO.getItemShopId().equals(shopIdByStr)) {
                                    if (subclassDTO.getGoodsQuantity() == 1) {
                                        // 判断商品个数
                                        goodsRtpPrice = subclassDTO.getRedPacketSumMoney();
                                        // 优惠活动中平台承担的金额
                                        subclassDTO.setOrderGoodsPlatformBear(subclassDTO.getRedPacketSumMoney());
                                    } else {
                                        if (sizeA == i + 1 && sizeB == n + 1 && sizeC == j + 1) {
                                            goodsRtpPrice=subclassDTO.getRedPacketSumMoney().subtract(subclassDTO.getOrderGoodsRptPrice());
                                            subclassDTO.setOrderGoodsPlatformBear(subclassDTO.getRedPacketSumMoney().subtract(subclassDTO.getOrderGoodsAddPlatformBear()));
                                        } else {
                                            BigDecimal itemShopPrice = detailedPrice.getShippingList().get(i)
                                                    .getItemShopPrice();
                                            subclassDTO.setOrderGoodsPlatformBear(goodsPrice.multiply(goodsAmount)
                                                    .divide(itemShopPrice, 2, RoundingMode.HALF_UP)
                                                    .multiply(subclassDTO.getRedPacketSumMoney().setScale(2, RoundingMode.HALF_UP)));// 拆分比例价格);
                                            // 累加价格
                                            subclassDTO.setOrderGoodsAddPlatformBear(subclassDTO.getOrderGoodsAddPlatformBear().add(subclassDTO.getOrderGoodsPlatformBear()));
                                            // 赋值红包价格
                                            goodsRtpPrice = subclassDTO.getOrderGoodsPlatformBear();
                                            // 累加红包拆分价格
                                            subclassDTO.setOrderGoodsRptPrice(subclassDTO.getOrderGoodsRptPrice().add(goodsRtpPrice));

                                        }
                                    }
                                } else if (subclassDTO.getRedpacketTType() == 1 || subclassDTO.getRedpacketTType() == 2
                                        || subclassDTO.getRedpacketTType() == 6 || subclassDTO.getRedpacketTType() == 7) {
                                    // 普通红包比例拆分
                                    if (flag) {
                                        // 1件商品
                                        goodsRtpPrice = subclassDTO.getRedPacketSumMoney();
                                        subclassDTO.setOrderGoodsPlatformBear(subclassDTO.getRedPacketSumMoney());
                                    } else {
                                        // 多件商品,判断最后一件
                                        if (sizeA == i + 1 && sizeB == n + 1 && sizeC == j + 1) {
                                            goodsRtpPrice = subclassDTO.getRedPacketSumMoney().subtract(subclassDTO.getOrderGoodsRptPrice());
                                            subclassDTO.setOrderGoodsPlatformBear(subclassDTO.getRedPacketSumMoney().subtract(subclassDTO.getOrderGoodsAddPlatformBear()));
                                        } else {
                                            BigDecimal shopPrice = detailedPrice.getShippingList().get(i).getShopPrice();// 单个店铺总价
                                            // 拆分至每家店铺的红包再次拆分至每一个商品
                                            subclassDTO.setOrderGoodsPlatformBear(priceDTO.getOrderGoodsAmount()
                                                    .divide(shopPrice, 2, RoundingMode.HALF_UP)
                                                    .multiply(subclassDTO.getRedPacketSumMoney()).setScale(2, RoundingMode.HALF_UP));
                                            goodsRtpPrice = subclassDTO.getOrderGoodsPlatformBear();
                                            subclassDTO.setOrderGoodsRptPrice(subclassDTO.getOrderGoodsRptPrice().add(goodsRtpPrice));
                                            subclassDTO.setOrderGoodsAddPlatformBear(subclassDTO.getOrderGoodsAddPlatformBear().add(subclassDTO.getOrderGoodsPlatformBear()));
//
                                        }
                                    }
                                }
                            }

                            // 优惠券&红包都不使用
                            if(goodsShippingFee == null){
                                goodsShippingFee = BigDecimal.ZERO;
                            }

                            if (!CollectionUtils.isEmpty(priceDTO.getAvaliableGoods()) && priceDTO.getAvaliableGoods().contains(goodsId)) {
                                if (sizeA == i + 1 && sizeB == n + 1 && sizeC == j + 1) {
                                    subclassDTO.setPlatformVoucherRptPrice(subclassDTO.getPlatformVoucherShopPrice().subtract(subclassDTO.getPlatformVoucherRptAddPrice()));
                                } else {
                                    // 购物津贴拆分至goods
                                    BigDecimal allowanceShopPrice = detailedPrice.getShippingList().get(i)
                                            .getAllowanceShopPrice();
                                    subclassDTO.setPlatformVoucherRptPrice(goodsPrice.multiply(goodsAmount)
                                            .divide(allowanceShopPrice, 2, BigDecimal.ROUND_HALF_UP)
                                            .multiply(subclassDTO.getPlatformVoucherShopPrice()).setScale(2, BigDecimal.ROUND_HALF_UP));
                                    subclassDTO.setPlatformVoucherRptAddPrice(subclassDTO.getPlatformVoucherRptAddPrice().add(subclassDTO.getPlatformVoucherRptPrice()));

                                }
                            }


                            BigDecimal price = goodsPrice.multiply(goodsAmount);
                            //商品减去会员折扣好价格  用于计算plus会员价格
                            BigDecimal plusprice = new BigDecimal(0);
                            subclassDTO.setPaymentRealPrice(price.add(goodsShippingFee));
                            BigDecimal orderDiscountFee = new BigDecimal(0);// 总优惠金额
                            Double gradeDiscount  = 0.0;
                            //会员折扣
                            if(null != cp.getMemberClassId() && 0 != cp.getMemberClassId()){
                                ResponseResult resp = baseServiceClient.getMemberNameByClassId(cp.getMemberClassId().toString());
                                Map<String,Object> map = (Map<String, Object>) resp.getData();
                                gradeDiscount = (Double) map.get("gradeDiscount");
                                // 总优惠金额
                                System.out.println(priceDTO.getOrderGoodsAmount());
                                System.out.println(priceDTO.getOrderGoodsAmount().multiply(new BigDecimal(gradeDiscount)).setScale(2, RoundingMode.HALF_UP));
                                subclassDTO.setGoodsMemberDiscount(subclassDTO.getPaymentRealPrice()
                                            .subtract(goodsShippingFee).subtract(((subclassDTO.getPaymentRealPrice().subtract(goodsShippingFee))
                                                .multiply(new BigDecimal(gradeDiscount)).setScale(2, RoundingMode.HALF_UP))));

                                orderDiscountFee = subclassDTO.getGoodsMemberDiscount().add(orderDiscountFee);
                                subclassDTO.setBaseMemberDiscount(subclassDTO.getBaseMemberDiscount().add(subclassDTO.getGoodsMemberDiscount()));

                                //商品减去会员折扣好价格  用于计算plus会员价格
                                plusprice = subclassDTO.getPaymentRealPrice().subtract(goodsShippingFee).subtract(subclassDTO.getGoodsMemberDiscount());
                                subclassDTO.setPaymentRealPrice(subclassDTO.getPaymentRealPrice().subtract(subclassDTO.getGoodsMemberDiscount()));

                            }

                            //plus会员优惠金额
                            //查询是否为plus商品
                            if (selectplusmember.getCode() == 1 && usedamout.compareTo(new BigDecimal(0)) > 0) {
                                Integer integer = goodServiceClient.queryGoodsIsPlus(wsqrList.get(j).getCommonId());
                                if (integer == 1) {
                                    priceDTO.setPlusOrder(1);
                                    //plus会员折扣
                                    Map<String,Object> map= (Map<String, Object>) selectplusmember.getData();
                                    BigDecimal data = new BigDecimal(String.valueOf(map.get("discount")));
                                    data = new BigDecimal(1).subtract(data);
                                    //plus商品  会员折扣金额
                                    priceDTO.setPlusgoodsprice(plusprice.multiply(data).setScale(2, RoundingMode.HALF_UP));

                                    //判断可用额度
                                    if (usedamout.compareTo(new BigDecimal(-1)) != 0){
                                        if (priceDTO.getPlusgoodsprice().compareTo(usedamout) > 0){
                                            priceDTO.setPlusgoodsprice(usedamout);
                                        }
                                        usedamout = usedamout.subtract(priceDTO.getPlusgoodsprice());
                                    }
                                    //总优惠金额
                                    priceDTO.setPlusgoodstotal(priceDTO.getPlusgoodstotal().add(priceDTO.getPlusgoodsprice()));
                                    //支付金额
                                    subclassDTO.setPaymentRealPrice(subclassDTO.getPaymentRealPrice().subtract(priceDTO.getPlusgoodsprice()).setScale(2,BigDecimal.ROUND_HALF_UP));
                                    //将plus会员折扣金额加入会员金额
                                    subclassDTO.setBaseMemberDiscount(subclassDTO.getBaseMemberDiscount().add(priceDTO.getPlusgoodsprice()));

                                    goodsPlusDis = 1;

                                    //更新plus信息表已用额度
                                    hashMap.put("userId",ui.getUserId());
                                    hashMap.put("usedAmout",priceDTO.getPlusgoodsprice());
                                    hashMap.put("totalAmount",priceDTO.getPlusgoodsprice());
                                    userServiceClient.updateUserPluslimit(hashMap);
                                }
                            }

                            subclassDTO.setPaymentRealPrice(subclassDTO.getPaymentRealPrice().subtract(couponSumMoney).subtract(subclassDTO.getOrderGoodsPlatformBear())
                                    .subtract(subclassDTO.getPlatformVoucherRptPrice()).setScale(2, RoundingMode.HALF_UP));

                            if (subclassDTO.getPaymentRealPrice().compareTo(new BigDecimal(0)) < 0){
                                subclassDTO.setPaymentRealPrice(new BigDecimal(0));

                            }

                            BigDecimal catCommission = orderGoodsMapper.queryCatCommission(catId);//查询分类抽佣比例
                            if(null == catCommission){
                                catCommission = new BigDecimal(0);
                            }
                            //计算 商家抽佣
                            catCommission = catCommission.divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP);
                            //计算平台抽佣
                            subclassDTO.setOrderGoodsCommission(subclassDTO.getPaymentRealPrice()
                                       .subtract(goodsShippingFee).multiply(catCommission)
                                       .setScale(2, RoundingMode.HALF_UP));
                            subclassDTO.setOrderBaseCommission(subclassDTO.getOrderBaseCommission()
                                       .add(subclassDTO.getOrderGoodsCommission())
                                       .setScale(2, RoundingMode.HALF_UP));

                            // 供应商待发货订单
                            if (null != subclassDTO.getSupplyShopId() && subclassDTO.getSupplyShopId().intValue() != shopId.intValue()) {
                                priceDTO.setDropShipping(1);
                                //因为同步供应商的商品不能加购物车 所以一个订单对应一个商品
                                //如果是代发货的订单 存放供应商的商品价格 和 商品总价
                                //根据当前商品查询 供应商 商品信息
                                Map<String,Object> param = new HashedMap();
                                param.put("commonId",commonId);
                                param.put("goodsId",goodsId);
                                ResponseResult supperGoodsInfo = goodServiceClient.querySupplierGoodsPrice(param);
                                Map<String,Object> respData2  = (Map<String,Object>) supperGoodsInfo.getData();
                                BigDecimal supperGoodsPrice = new BigDecimal(respData2.get("goodsPrice").toString());
                                supperGoodsPrice = supperGoodsPrice.multiply(new BigDecimal(goodsNum)).setScale(2, RoundingMode.HALF_UP);
                                //计算供应商 抽佣
                                BigDecimal ordesupperCommission = supperGoodsPrice.multiply(catCommission).setScale(2, RoundingMode.HALF_UP);

                                //如果是待发货的订单 查询平台对 经销订单抽佣的经销规则  只针对 经销订单
                                ResponseResult resp = baseServiceClient.settingDistribute();
                                Map<String,Object> map = (Map<String, Object>) resp.getData();
                                if(null != map){
                                    //自销抽佣开关  1 开 2 关
                                    Integer value1 = Integer.valueOf(map.get("value1").toString());
                                    if(2 == value1){
                                        subclassDTO.setOrderGoodsCommission(new BigDecimal(0));
                                        subclassDTO.setOrderBaseCommission(new BigDecimal(0));

                                    }
                                    //经销抽佣开关 1 开 2 关
                                    Integer value2 = Integer.valueOf(map.get("value2").toString());
                                    if(2 == value2){
                                        ordesupperCommission = new BigDecimal(0);
                                    }
                                }

                                respData2.put("priceSum",supperGoodsPrice);
                                respData2.put("ordesupperCommission",ordesupperCommission);
                                respData2.put("paymentAmount",supperGoodsPrice.add(goodsShippingFee));
                                respData2.put("goodsNum",goodsNum);
                                respData2.put("orderId",subclassDTO.getOrderId());

                                //将供应商订单信息存入数据库
                                orderBaseMapper.insertSupperOrderBase(respData2);
                            }

                            manjianDiscount = manjianDiscount.setScale(2, RoundingMode.HALF_UP);
                            manzheDiscount = manzheDiscount.setScale(2, RoundingMode.HALF_UP);
                            BigDecimal shopPrice = detailedPrice.getShippingList().get(i).getShopPrice();// 每家店铺商品总价(不包含运费，优惠价格)
                            orderDiscountFee = orderDiscountFee.add(manjianDiscount).add(manzheDiscount);// 满减活动 + 会员折扣
                            subclassDTO.setOrderBasePaymentAmount(shopPrice.add(shippingFee).subtract(priceDTO.getOrderRptPrice()).subtract(orderDiscountFee));
//                            subclassDTO.setPaymentRealPrice(subclassDTO.getPaymentRealPrice().subtract(manjianDiscount).subtract(manzheDiscount));

                            if (subclassDTO.getOrderBasePaymentAmount().compareTo(new BigDecimal(0)) < 0){
                                subclassDTO.setOrderBasePaymentAmount(new BigDecimal(0));
                            }


                            if( null != cp.getVirtualGoods() &&  0 == cp.getVirtualGoods() ){
                                Map<String,String> map = new HashMap<>();
                                map.put("goodsId",String.valueOf(goodsId));
                                ResponseResult resp = goodServiceClient.queryVirtualgoods(map);
                                respData  = (Map<String,Object>) resp.getData();
                            }

                            // 计算商品经销佣金和供应商佣金
                            double dealer = wsqrList.get(j).getDealerCommission() == null ? 0 : Double.parseDouble(wsqrList.get(j).getDealerCommission()) / 100;
                            double supply = wsqrList.get(j).getSupplyCommission() == null ? 0 : Double.parseDouble(wsqrList.get(j).getSupplyCommission()) / 100;
                            BigDecimal dealerCommission = subclassDTO.getPaymentRealPrice().multiply(new BigDecimal(dealer).setScale(2, RoundingMode.HALF_UP));
                            BigDecimal supplyCommission = subclassDTO.getPaymentRealPrice().multiply(new BigDecimal(supply).setScale(2, RoundingMode.HALF_UP));
                            totalDealerCommission = totalDealerCommission.add(dealerCommission);
                            totalSupplyCommission = totalSupplyCommission.add(supplyCommission);

                            //查询积分商品所需 的积分
                            Integer needIntegral = orderBaseMapper.getGoodsIntegral(goodsId);
                            if( null != needIntegral) {
                                needIntegral = 0;
                            }
//                            if (activityStatus == 5 &&
//                                    (shippingListDTO.getShopManjianDiscount().compareTo(BigDecimal.ZERO) > 0 ||
//                                    shippingListDTO.getShopManzheDiscount().compareTo(BigDecimal.ZERO) > 0)) {
//                                subclassDTO.setPaymentRealPrice(shippingListDTO.getGoodsAmountList().get(n));
//                            }
                            if(shippingListDTO.getPromotionIdList()!=null&& !shippingListDTO.getPromotionIdList().isEmpty()){
                                promotionId = shippingListDTO.getPromotionIdList().get(n);
                            }
                            BigDecimal fullReductionDiscount = null;
                            BigDecimal fullFoldingDiscount = null;
                            BigDecimal paymentRealPrice = subclassDTO.getPaymentRealPrice();
                            if (shippingListDTO.getManjianMap() != null){
                                fullReductionDiscount = shippingListDTO.getManjianMap().get(goodsId);
                                paymentRealPrice = paymentRealPrice.subtract(fullReductionDiscount == null ? BigDecimal.ZERO : fullReductionDiscount);
                            }
                            if (shippingListDTO.getManjianMap() != null){
                                fullFoldingDiscount = shippingListDTO.getManzheMap().get(goodsId) ;
                                paymentRealPrice = paymentRealPrice.subtract(fullFoldingDiscount == null ? BigDecimal.ZERO : fullFoldingDiscount);
                            }
                            paymentRealPrice = paymentRealPrice.setScale(2, RoundingMode.HALF_UP);
                            // 创建订单(orderGoods)
                            boolean isInsertByOrderGoodsSuccess = orderGoodsMapper.insertByOrderGoods(totalGoodsShippingFee,orderId, shopId,
                                    shopName, goodsId, commonId, ui.getUserId(), goodsName, catId, goodsSpec, goodsPrice, goodsNum,
                                    goodsImage, goodsShippingFee, priceDTO.getOrderGoodsAmount(), subclassDTO.getOrderGoodsPlatformBear(),
                                    paymentRealPrice, orderGoodsStatus, orderGoodsEvaluationStatus, goodsRtpPrice,
                                    couponSumMoney,  subclassDTO.getPlatformVoucherRptPrice(), goodsReturnStatus, goodsRefundStatus,
                                    orderGoodsTime, orderGoodsIdDeliver, promotionId, subclassDTO.getSmallOrder(),needIntegral, dealerCommission,
                                    supplyCommission,subclassDTO.getOrderGoodsCommission(),subclassDTO.getGoodsMemberDiscount(),
                                    orderDiscountFee,priceDTO.getPlusgoodsprice(),goodsPlusDis,fullReductionDiscount,fullFoldingDiscount,
                                    activityUnitPrice,goodsPromotionId,voucherId);



                            // 存放goodsnameConsumeTrade
                            List<String> goodsNameList = new ArrayList<>();
                            goodsNameList.add(goodsName);
                            ctp.setGoodsName(goodsNameList);
                            // 存放goodsnameConsumeRecord
                            crp.setGoodsName(goodsNameList);
                            // 存放卖家商品名
                            crb.setGoodsName(goodsNameList);
                            if (!isInsertByOrderGoodsSuccess) {
                                goodsPlusDis = 0;//归0
                                return ResponseResult.fail(0, "创建订单失败！");
                            }
                            Integer fxType = 1;// 1 是通过分享页下单  2 是通过 商城直接下单
                            //通过推广页购买商品
                            if (null != cp.getShareUserId() && !Objects.equals(cp.getShareUserId(), "0") && null != cp.getShareType()
                                    && (cp.getShareType().equals(CommonType.goodsShareType.VK_COMMISSION.getCode()) ||  cp.getShareType().equals(CommonType.goodsShareType.VK_INVITE.getCode()) )
                                    && !ui.getUserId() .equals(cp.getShareUserId())) {
                                vkFlag = true;
                                //创建分销佣金订单
                                OrderCommissionVO orderCommission = fxService.addOrderCommission(wsqrList.get(j), wapList.get(i), ui, cp.getShareUserId(), orderId, subclassDTO.getPaymentRealPrice(),fxType);
                                if (null != orderCommission) {
                                    orderCommission.setFxTg(1);//分享
                                    orderCommissionList.add(orderCommission);
                                }
                            }else{
                                fxType = 2;
                                //微客通过正常页面购买分销商品
                                //获取微客绑定的上级
                                Map<String,String> map2 = new HashMap<>(8);
                                map2.put("userId",ui.getUserId());
                                ResponseResult resultResp = userServiceClient.queryVKUserInfo(map2);
                                if(null != resultResp ){//不为null证明是微客否则是普通用户
                                    VKUserInfoVO shareUserInfo = JSON.parseObject(JSON.toJSONString(resultResp.getData()),VKUserInfoVO.class);
                                    if(null != shareUserInfo.getShopUserId() && !(" ".equals(shareUserInfo.getShopUserId()))){
                                        cp.setShareUserId(shareUserInfo.getShopUserId());
                                        //创建分销佣金订单
                                        OrderCommissionVO orderCommission = fxService.addOrderCommission(wsqrList.get(j), wapList.get(i), ui, cp.getShareUserId(), orderId, subclassDTO.getPaymentRealPrice(),fxType);
                                        if (null != orderCommission) {
                                            orderCommission.setFxTg(2);//推广
                                            orderCommissionList.add(orderCommission);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if(null != priceDTO.getTotalIntegral()){
                        //存放积分商品兑换所需的积分
                        RedisUtil.set(YFConfig.YF_USERINTEGRALYPAID + "--" + cp.getToken() + "--" + ui.getUserId(),
                                priceDTO.getTotalIntegral().toString(), 1200);
                    }
                    if ( null == priceDTO.getTotalPrice()) {
                        priceDTO.setTotalPrice(new BigDecimal(0));
                    }
                    // 存放付款金额
                    RedisUtil.set(YFConfig.YF_USERAMOUNTACTUALLYPAID + "--" + cp.getToken() + "--" + ui.getUserId(),
                            priceDTO.getTotalPrice().toString(), 1200);
                    String orderDate = DateUtils.getYear() + "-" + DateUtils.getMonth() + "-"
                            + DateUtils.getDay();
                    // 买家评价状态
                    // 订单状态
                    BigDecimal shopPrice = detailedPrice.getShippingList().get(i).getShopPrice();// 每家店铺商品总价(不包含运费，优惠价格)
                    BigDecimal orderDiscountFee = new BigDecimal(0);// 总优惠金额
                    int orderType = CommonType.orderType.GOODS_TYPE.getCode();
                    subclassDTO.setOrderBasePaymentAmount(
                            shopPrice.add(shippingFee).subtract(subclassDTO.getPlatformVoucherShopPrice())
                                     .subtract(subclassDTO.getRedPacketSumMoney())
                                     .subtract(subclassDTO.getCouponPrice())
                                     .subtract(shippingListDTO.getShopManjianDiscount()==null?BigDecimal.ZERO:shippingListDTO.getShopManjianDiscount())
                                     .subtract(shippingListDTO.getShopManzheDiscount()==null?BigDecimal.ZERO:shippingListDTO.getShopManzheDiscount())
                                     .subtract(subclassDTO.getBaseMemberDiscount())
                    );

                    //使用无门槛红包订单金额小于0
                    if (subclassDTO.getOrderBasePaymentAmount().compareTo(new BigDecimal(0)) < 0){
                        subclassDTO.setOrderBasePaymentAmount(new BigDecimal(0));
                    }
                    // 总优惠金额
                    orderDiscountFee = shopPrice.add(shippingFee)
                                      .subtract(subclassDTO.getOrderBasePaymentAmount())
                                      .subtract(priceDTO.getManjianDiscountBase())
                                      .subtract(priceDTO.getManzheDiscountBase())
                                      .subtract(subclassDTO.getBaseMemberDiscount());

                    ShopUserMessageResultVO shopUserMessageResult = businessServiceClient.queryUserId(shopId);
                    if (null != shopUserMessageResult || null != cp.getIntegralGoods() && cp.getIntegralGoods() == 0) {
                        //orderBase新增订单信息
                       ResponseResult result= insertOrderBase(cp,dto,priceDTO,ui, subclassDTO, shopUserMessageResult, ctp,  crp,  crb, vkFlag, shopId, shopName,  orderGoodsTime,
                                shopPrice, orderDiscountFee,  shippingFee, buyerMessage,  districtId, request,respData, totalDealerCommission, totalSupplyCommission,
                                StringUtils.isEmpty(priceDTO.getVoucherIdList())? "0": priceDTO.getVoucherIdList().get(i),  orderList, orderCancelMinute, shippingListDTO);
                        if (result.getCode()!=CommonStatusEnum.SUCCESS.getCode()) {
                            GlobalTransactionContext.reload(RootContext.getXID()).rollback();
                            return ResponseResult.fail(0, "生成订单失败！");
                        }
                        if (result.getData() != null){
                            orderCancelTime=Long.valueOf(result.getData().toString());
                        }
                    }
                    if(null != cp.getGoodsCat() && cp.getGoodsCat()){
                        // 下单成功，删除购物车商品
                        orderUserCartMapper.batchDeleteGoods(ui.getUserId(), goodsIdList);
                    }
                    orderId=subclassDTO.getOrderId();
                }
                // 批量插入分佣订单
                if (!CollectionUtils.isEmpty(orderCommissionList)) {
                    orderCommissionMapper.insertBatch(orderCommissionList);
                }

                // 更新红包优惠券状态
                Map<String, Object> statusMap = new HashMap<>();
                statusMap.put("redpacketId", priceDTO.getRedpacketId());
                statusMap.put("platformVoucherCode", priceDTO.getPlatformVoucherCode());
                statusMap.put("voucherId", priceDTO.getVoucherIdList());
                statusMap.put("type", "1");
                statusMap.put("orderId", orderId);
                ResponseResult salesResp = activityServiceClient.updateSalesPrm(statusMap);
                if (salesResp.getCode() != CommonStatusEnum.SUCCESS.getCode()) {
                    return salesResp;
                }

                // 拼团传值
                JoinPintuanParamVO jpp = new JoinPintuanParamVO();
                if (subclassDTO.getType() != null && 1 != subclassDTO.getType()) {
                    jpp.setType(subclassDTO.getType());
                    jpp.setToken(cp.getToken());
                    jpp.setMarkId(subclassDTO.getMarkId());
                    jpp.setUserId(ui.getUserId());
                    jpp.setIsMark(subclassDTO.getIsMark());
                    jpp.setGoodsId(subclassDTO.getGroupBookingGoodsId());
                    jpp.setCommonId(subclassDTO.getPinCommonId());
                    jpp.setOrderId(subclassDTO.getPaymentNumber());
                    ResponseResult getReturnPara = activityServiceClient.addJoinPintuan(jpp);
                    Integer code = getReturnPara.getCode();
                    if (code == 2) {
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        return ResponseResult.fail(0, "拼团失败！");
                    } else {
                        if (RedisUtil.exists(subclassDTO.getMarkId())) {
                            String checkGroupBookingStatusPara = RedisUtil.get(subclassDTO.getMarkId());
                            ExpireMarkIdUpdateParamVO expireMarkIdUpdateParam = JSON.parseObject(checkGroupBookingStatusPara,
                                    ExpireMarkIdUpdateParamVO.class);
                            checkGroupBookingStatus(expireMarkIdUpdateParam);
                        }
                    }
                }
                OrderInfoVO info = new OrderInfoVO();
                // 纯积分订单
                if (null != cp.getIntegralGoods() && cp.getIntegralGoods() == 0) {
                    if (detailedPrice.getTotalPrice() == null) {
                        Map<Object, Object> map = new HashMap<>();
                        map.put("token", cp.getToken());
                        map.put("orderIdList", subclassDTO.getPaymentNumber());
                        map.put("type", 12);
                        rr = payMentServiceClient.payMentUnifyInlet(map);
                        if (rr.getCode() != CommonStatusEnum.SUCCESS.getCode()) {
                            return rr;
                        }
                        info.setIsIntegral(CommonType.commonStatus.YES.getCode());
                    } else {
                        info.setIsIntegral(CommonType.commonStatus.NO.getCode());
                    }
                }
                info.setPaymentNumber(subclassDTO.getPaymentNumber());
                info.setOrderIdList(orderList);
                info.setOrderCancelTime(orderCancelTime);
                return ResponseResult.success(info);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.fail(e.getMessage());
        }

    }



    /**
     * 处理满减赠折优惠
     * @param sp
     * @param sl
     * @param mjzzIds
     * @param mjzzAmounts
     * @param mjzzRules
     */

    private void DealMjzzPromotion(ShopParaVO sp,ShippingListVO sl,HashSet<ManjianzengzheDTO> mjzzIds, Map<Integer,BigDecimal> mjzzAmounts,Map<Integer,Object> mjzzRules, Map<Integer,Integer> mzNum)throws Exception{
        for(ManjianzengzheDTO dto:mjzzIds){
            Integer pid = dto.getPromotionId();
            //对每个活动进行处理
            List<ManjianzengzheGoodsRuleQueryDTO> ruleList =
                    (List<ManjianzengzheGoodsRuleQueryDTO>) mjzzRules.get(pid);
            BigDecimal price = mjzzAmounts.get(pid);
            HashSet<BigDecimal> meetAmountList = new HashSet<BigDecimal>(); //满足金额-满减满赠
            BigDecimal meetAmountMax = BigDecimal.ZERO; //符合条件的最大满足金额-满减满赠
            Integer meetNum = null==mzNum.get(pid)?0:mzNum.get(pid); //单个活动的满折商品数量
            BigDecimal meetNumBD = new BigDecimal(meetNum);

            Map<BigDecimal, ManjianzengzheGoodsRuleQueryDTO> ruleMap = new HashMap<>(); //折扣内容
            String mainDiscountContent = null;
            Integer mainDiscountType = 0; //折扣类型 1-满减赠 3-满折

            for(ManjianzengzheGoodsRuleQueryDTO rule : ruleList) {
                BigDecimal meetAmount = rule.getMeetAmount();
                meetAmountList.add(meetAmount);
                ruleMap.put(meetAmount,rule);
                mainDiscountType = rule.getDiscountType(); //一个活动对应的只能是一种折扣类型

            }
            //获取最大满足金额/数量
            for(BigDecimal meetAm:meetAmountList){
                //满减赠活动 meetAmountMax为最大满足金额
                if(1 == mainDiscountType) {
                    if (price.compareTo(meetAm) == 0) {
                        meetAmountMax = meetAm;
                        break;
                    } else if (price.compareTo(meetAm) > 0) {
                        if (meetAm.compareTo(meetAmountMax) > 0) {
                            meetAmountMax = meetAm;
                        }
                    }
                    //满折活动 meetAmountMax为最大满足数量
                }else if(3 == mainDiscountType){
                    if (meetNumBD.compareTo(meetAm) == 0) {
                        meetAmountMax = meetAm;
                        break;
                    } else if (meetNumBD.compareTo(meetAm) > 0) {
                        if (meetAm.compareTo(meetAmountMax) > 0) {
                            meetAmountMax = meetAm;
                        }
                    }
                }
            }
            BigDecimal mjzzDiscount = BigDecimal.ZERO;
            //获取折扣内容
            ManjianzengzheGoodsRuleQueryDTO mjzzRule = ruleMap.get(meetAmountMax);
            if(null != mjzzRule) {
                mainDiscountType = mjzzRule.getDiscountType();
                mainDiscountContent = mjzzRule.getDiscountContent();
                Integer hasGiveaway = mjzzRule.getHasGiveaway();
                if (1 == mainDiscountType) {//满减
                    if(null != mainDiscountContent && !mainDiscountContent.isEmpty()) {
                        BigDecimal mjDiscount = new BigDecimal(mainDiscountContent);
                        mjzzDiscount = mjDiscount.setScale(2, RoundingMode.HALF_UP);
                        sl.setShopManjianDiscount(sl.getShopManjianDiscount().add(mjzzDiscount));
                        sp.setTotalManjianDiscount(sp.getTotalManjianDiscount().add(mjzzDiscount));
                    }
                } else if (3 == mainDiscountType) {//满折
                    if(null != mainDiscountContent && !mainDiscountContent.isEmpty()) {
                        BigDecimal mzDiscount = BigDecimal.valueOf(0.1 * Double.parseDouble(mainDiscountContent)).setScale(2,RoundingMode.HALF_UP);
                        mjzzDiscount = price.subtract(price.multiply(mzDiscount)).setScale(2,RoundingMode.HALF_UP);
                        sl.setShopManzheDiscount(sl.getShopManzheDiscount().add(mjzzDiscount));
                        sp.setTotalManzheDiscount(sp.getTotalManzheDiscount().add(mjzzDiscount));
                        sl.getPromotionIdList().set(dto.getIndex(), 6);
                    }
                }
                List<BigDecimal> goodsAmountList = sl.getGoodsAmountList();
                int size = dto.getIndexList().size();
                Map<Integer,BigDecimal> manjianMap = new HashMap<>();
                Map<Integer,BigDecimal> manzheMap = new HashMap<>();
                for (int i = 0; i < size; i++) {
                    int index = dto.getIndexList().get(i);
                    if (mjzzDiscount.compareTo(BigDecimal.ZERO) > 0) {
                        BigDecimal scale = mjzzDiscount.divide(price, 6, RoundingMode.HALF_EVEN);
                        sl.setScale(scale);
                        if (null != mainDiscountContent && !mainDiscountContent.isEmpty()) {
                            BigDecimal amountScale = 3 == mainDiscountType ? scale.setScale(2, RoundingMode.HALF_UP) : scale;
                            BigDecimal amount = sl.getGoodsAmountList().get(index);
                            BigDecimal goodsAmount = amount.multiply(BigDecimal.ONE.subtract(amountScale)).setScale(2, RoundingMode.HALF_UP);
                            goodsAmountList.set(index, goodsAmount);
                            sl.setGoodsAmountList(goodsAmountList);
                            BigDecimal discount = dto.getGoodsPriceList().get(i).divide(price,2,RoundingMode.HALF_UP).multiply(mjzzDiscount);
                            if (1 == mainDiscountType) {//满减
                                manjianMap.put(dto.getGoodsIdList().get(i),discount);
                            } else if (3 == mainDiscountType) {//满折
                                manzheMap.put(dto.getGoodsIdList().get(i),discount);
                            }
                        }
                    }
                }
                sl.setManjianMap(manjianMap);
                sl.setManzheMap(manzheMap);
                if(1 == hasGiveaway) {//满赠
                    String giveawayName = mjzzRule.getGiveawayName();
                    String giveawayImage = mjzzRule.getGiveawayImage();
                    String spId = sl.getShopId().toString();
                    Map<String,String> giveawayMap = new HashMap<>();
                    giveawayMap.put("goodsId", dto.getGoodsId().toString());
                    giveawayMap.put("giveawayGoodsId", mjzzRule.getGoodsId().toString());
                    String giveawayId = mjzzRule.getGiveawayId().toString();
                    giveawayMap.put("giveawayId",giveawayId);
                    giveawayMap.put("giveawayName",giveawayName);
                    giveawayMap.put("giveawayImage",giveawayImage);
                    if(null==sl.getShopGiveawayList()){
                        List<Map<String, String>> giveawayList = new ArrayList<>();
                        sl.setShopGiveawayList(giveawayList);
                    }
                    sl.getShopGiveawayList().add(giveawayMap);
                    if(null==sp.getGiveawayList()){
                        List<Map<String, String>> totalGiveawayList = new ArrayList<>();
                        sp.setGiveawayList(totalGiveawayList);
                    }
                    Map<String, String> totalGiveawayMap = new HashMap<>(giveawayMap);
                    totalGiveawayMap.put("shopId",spId);
                    sp.getGiveawayList().add(totalGiveawayMap);
                }
            }
        }

    }
    /**
     * 查看拼团状态
     *
     * @param para
     * @return
     */
    public boolean checkGroupBookingStatus(ExpireMarkIdUpdateParamVO para) {
        boolean flag = false;
        List<String> orderIdList = para.getOrderIdList();
        Integer status = para.getStatus();
        try {
            if (status == 1) {
                // 拼团成功，改变订单状态
                boolean isUpdateBaseStatus = orderBaseMapper.updateGroupBookingBaseStatus(orderIdList);
                flag = true;
            } else {
                // 拼团失败
                boolean isUpdateBaseStatus = false;
                boolean isUpdateGoodsStatus = false;
                // U支付号
                for (String orderId : orderIdList) {
                    String cancelTime = DateUtils.getNowDateToString();
                    String payNumber = orderBaseMapper.queryPayNumber(orderId);
                    isUpdateBaseStatus = orderBaseMapper.updateGroupBookingBaseOrderStatus(orderId, cancelTime);
                    isUpdateGoodsStatus = orderBaseMapper.updateGroupBookingGoodsOrderStatus(payNumber);
                }
                if (isUpdateBaseStatus && isUpdateGoodsStatus ) {
                    flag = true;
                }
            }
        } catch (Exception e) {
        }
        return flag;
    }


    public CreateOrderDTO getData(UserInfoVO ui,CommonParameterVO cp){
        CreateOrderDTO dto=new CreateOrderDTO();

        Integer orderIsShopTake = 2;
        if(cp != null && cp.getOrderIsShopTake() != null){
            orderIsShopTake = cp.getOrderIsShopTake();
        }
        Integer payMentCode = cp.getPaymentCode();
        if(null == payMentCode){
            payMentCode = 1;
        }


        Integer treasureOrderShopId = cp.getTreasureOrderShopId();
         // 收货人姓名
        String orderReceiverName = cp.getOrderReceiverName();
        // 收货人地址
        String orderReceiverAddress = cp.getOrderReceiverAddress();
        // 收货人联系方式
        String orderReceiverContact = cp.getOrderReceiverContact();
        // 收货人省Id
        Integer orderReceiverProvinceId = cp.getOrderReceiverProvinceId();
        // 收货人市Id
        Integer orderReceiverCityId = cp.getOrderReceiverCityId();
        // 收货人区Id
        Integer orderReceiverAreaId = cp.getOrderReceiverAreaId();
        //判断商品是否是虚拟商品
        if(null != cp.getVirtualGoods() && 0 == cp.getVirtualGoods()){
            orderReceiverName = ui.getUserName();
            orderReceiverContact = ui.getUserMobile();
            //虚拟订单不需要 收货地址
            orderReceiverAddress = "";
            orderReceiverProvinceId = 0;
            orderReceiverCityId = 0;
            orderReceiverAreaId = 0;
        }
        //判断商品是否是门店商品
        if(null != cp.getOrderIsShopTake() && 1 == cp.getOrderIsShopTake()){
            //虚拟订单不需要 收货地址
            orderReceiverAddress = "";
            orderReceiverProvinceId = 0;
            orderReceiverCityId = 0;
            orderReceiverAreaId = 0;
        }
        // 订单来源
        dto.setOrderFromNum(cp.getPlatForm());
        dto.setGoodsIds(cp.getGoodsIds());
        dto.setOrderIsShopTake(orderIsShopTake);
        dto.setPayMentCode(payMentCode);
        dto.setTreasureOrderShopId(treasureOrderShopId);
        dto.setOrderReceiverName(orderReceiverName);
        dto.setOrderReceiverAddress(orderReceiverAddress);
        dto.setOrderReceiverContact(orderReceiverContact);
        dto.setOrderReceiverProvinceId(orderReceiverProvinceId);
        dto.setOrderReceiverCityId(orderReceiverCityId);
        dto.setOrderReceiverAreaId(orderReceiverAreaId);
        return dto;

    }


    public PriceDTO getPriceData(ShopParaVO detailedPrice){
        PriceDTO dto=new PriceDTO();

        String redpacketId = detailedPrice.getRedpacketId();// 红包编码
        String platformVoucherCode = detailedPrice.getPlatformVoucherCode();// 平台优惠券code
        BigDecimal platformVoucherPrice = detailedPrice.getPlatformVoucherPrice();// 平台优惠券金额
        List<Integer> avaliableGoods = detailedPrice.getAvaliableGoods();// 参与平台优惠券商品id
        BigDecimal totalPrice = detailedPrice.getTotalPrice();// 获取实付总价
        List<String> voucherIdList = detailedPrice.getVoucherIdList();// 优惠券id集合
        BigDecimal redPacketPrice = detailedPrice.getRedPacketPrice();// 获取红包金额
        Integer orderDiscountType = detailedPrice.getOrderDiscountType();// 优惠方式
        BigDecimal couponTotalPrice = detailedPrice.getCouponTotalPrice();// 获取总优惠券金额
        List<ShippingListVO> shippingLists = detailedPrice.getShippingList();
        BigDecimal manjianDiscountBase = BigDecimal.ZERO;// 获取满减优惠金额
        BigDecimal manzheDiscountBase = BigDecimal.ZERO;// 获取满折优惠金额
        List<Map<String, String>> totalGiveawayList = detailedPrice.getGiveawayList(); //获取赠品清单
        List<Map<String,String>> shopGiveawayList = new ArrayList<Map<String,String>>(); //店铺赠品清单
        String giveawayInfo = "";//赠品信息
        Integer redPacketStatus = detailedPrice.getRedPacketStatus();
        BigDecimal tradeDiscount = BigDecimal.ZERO;
        Integer totalIntegral = detailedPrice.getTotalIntegral();//积分商品所需积分之和
        Integer integralGoods = 1; //积分商品 0 是 1否

        //plus商品优惠金额
        BigDecimal plusgoodsprice = new BigDecimal(0);//plus商品优惠金额
        BigDecimal plusgoodstotal = new BigDecimal(0);//plus商品优惠总金额
        //是否为plus订单
        Integer  plusOrder = 0;
        // 供应商待发货订单
        Integer dropShipping = 2;


        if (null != couponTotalPrice) {
            tradeDiscount = couponTotalPrice.add(redPacketPrice);// 优惠价格
        }

        BigDecimal orderGoodsAmount = new BigDecimal(0);// 商品总价(不包含运费及优惠金额)
        BigDecimal orderRptPrice = new BigDecimal(0);// 红包拆分累加金额
        BigDecimal platformVoucherSplitPrice = BigDecimal.ZERO;// 购物津贴拆分价格
        BigDecimal redPacketSplitPrice = BigDecimal.ZERO;// 红包



        dto.setRedpacketId(redpacketId);
        dto.setPlatformVoucherCode(platformVoucherCode);
        dto.setPlatformVoucherPrice(platformVoucherPrice);
        dto.setAvaliableGoods(avaliableGoods);
        dto.setTotalPrice(totalPrice);
        dto.setVoucherIdList(voucherIdList);
        dto.setRedPacketPrice(redPacketPrice);
        dto.setOrderDiscountType(orderDiscountType);
        dto.setCouponTotalPrice(couponTotalPrice);
        dto.setShippingLists(shippingLists);
        dto.setManjianDiscountBase(manjianDiscountBase);
        dto.setManzheDiscountBase(manzheDiscountBase);
        dto.setTotalGiveawayList(totalGiveawayList);
        dto.setShopGiveawayList(shopGiveawayList);
        dto.setGiveawayInfo(giveawayInfo);
        dto.setRedPacketStatus(redPacketStatus);
        dto.setTradeDiscount(tradeDiscount);
        dto.setTotalIntegral(totalIntegral);
        dto.setIntegralGoods(integralGoods);
        dto.setPlusgoodsprice(plusgoodsprice);
        dto.setPlusgoodstotal(plusgoodstotal);
        dto.setPlusOrder(plusOrder);
        dto.setDropShipping(dropShipping);

        dto.setOrderGoodsAmount(orderGoodsAmount);
        dto.setOrderRptPrice(orderRptPrice);
        dto.setPlatformVoucherSplitPrice(platformVoucherSplitPrice);
        dto.setRedPacketSplitPrice(redPacketSplitPrice);


        return dto;
    }


    public SubclassDTO getSubData(ShippingListVO vo,StoreInformationVO svo,UserInfoVO ui,String paymentNumber){
        SubclassDTO dto=new SubclassDTO();

        String orderId = null;// 订单编号
        String sellerId = null;// 卖家id
        Integer pinCommonId = null;// 拼团commonid
        String markId = null;
        Integer type = null;
        Integer isMark = null;// 是否是团长
        Integer groupBookingGoodsId = null;
        Integer sizeA = null;
        Integer sizeB = null;
        Integer sizeC = null;

        BigDecimal orderSupplyPrice = BigDecimal.ZERO;
        Integer supplyShopId = null;
        String supplyShopName = null;

        BigDecimal orderGoodsCommission = new BigDecimal(0);//平台佣金
        BigDecimal orderBaseCommission =new BigDecimal(0);//平台佣金
        BigDecimal goodsMemberDiscount = new BigDecimal(0);//会员折扣
        BigDecimal baseMemberDiscount =new BigDecimal(0);//会员折扣

        Integer smallOrder = 0;
        Integer orderPromotionId = 0;// 是否参加活动值
        Integer groupbuyStatus = null;// 拼团状态值
        String orderBuyId = null;// markid
        Integer goodsQuantity = vo.getGoodsQuantity();// 每家店铺商品个数

        Integer redpacketTType = vo.getRedpacketTType();
        String itemShopId = vo.getItemShopId();// 单品红包所属shopid
        String allowanceShopId = vo.getAllowanceShopId();// 跨店满减所属shopid
        String shopLimit = vo.getShopLimit();// 获取店铺红包id
        Integer voucherStatus = vo.getVoucherStatus();// 优惠券使用状态

        BigDecimal orderCptPrice = new BigDecimal(0);// 代金券拆分累加金额
        BigDecimal paymentRealPrice = new BigDecimal(0);// goods表实付价格(含运费，去除红包拆分价格)
        BigDecimal orderGoodsRptPrice = new BigDecimal(0);// 商品红包拆分累加金额
        BigDecimal orderBasePaymentAmount = new BigDecimal(0);// base表实付金额
        BigDecimal redPacketSumMoney = new BigDecimal(0);// 记录店铺每次红包拆分金额
        BigDecimal platformVoucherShopPrice = new BigDecimal(0);// 平台优惠券店铺拆分
        BigDecimal orderGoodsPlatformBear = BigDecimal.ZERO;// 优惠活动中平台承担的金额
        BigDecimal orderGoodsAddPlatformBear = BigDecimal.ZERO;
        BigDecimal platformVoucherRptPrice = new BigDecimal(0);// 平台优惠券拆分
        BigDecimal platformVoucherRptAddPrice = BigDecimal.ZERO;

        BigDecimal couponPrice = vo.getCouponPrice();// 每家店铺使用优惠券价格
        BigDecimal redPacketGoodsSumMoney = new BigDecimal(0);// 记录商品每次红包拆分金额

        Integer invoiceId = svo.getInvoiceId();

        String invoiceName = null;// 发票信息
        //生成订单编号
        if (ui.getUserId().length() <= 8) {
            orderId = DateUtils.nowtime() + ui.getUserId() + DateUtils.randomLengthByTwo();// 订单编号
        } else {
            String oldUserId = ui.getUserId();
            String newUserId = oldUserId.substring(0, 4)
                    + oldUserId.substring(oldUserId.length() - 4);
            orderId = DateUtils.nowtime() + newUserId + DateUtils.randomLengthByTwo();// 订单编号
        }



        // 商户订单号
        dto.setPaymentNumber(paymentNumber);
        dto.setOrderId(orderId);
        dto.setSellerId(sellerId);
        dto.setPinCommonId(pinCommonId);
        dto.setMarkId(markId);
        dto.setType(type);
        dto.setIsMark(isMark);
        dto.setGroupBookingGoodsId(groupBookingGoodsId);
        dto.setSizeA(sizeA);
        dto.setSizeB(sizeB);
        dto.setSizeC(sizeC);

        dto.setOrderSupplyPrice(orderSupplyPrice);
        dto.setSupplyShopId(supplyShopId);
        dto.setSupplyShopName(supplyShopName);

        dto.setOrderGoodsCommission(orderGoodsCommission);
        dto.setOrderBaseCommission(orderBaseCommission);
        dto.setGoodsMemberDiscount(goodsMemberDiscount);
        dto.setBaseMemberDiscount(baseMemberDiscount);
        dto.setSmallOrder(smallOrder);
        dto.setOrderPromotionId(orderPromotionId);
        dto.setGroupbuyStatus(groupbuyStatus);
        dto.setOrderBuyId(orderBuyId);
        dto.setGoodsQuantity(goodsQuantity);

        dto.setRedpacketTType(redpacketTType);
        dto.setItemShopId(itemShopId);
        dto.setAllowanceShopId(allowanceShopId);
        dto.setShopLimit(shopLimit);
        dto.setVoucherStatus(voucherStatus);
        dto.setOrderCptPrice(orderCptPrice);
        dto.setPaymentRealPrice(paymentRealPrice);
        dto.setOrderGoodsRptPrice(orderGoodsRptPrice);
        dto.setOrderBasePaymentAmount(orderBasePaymentAmount);
        dto.setRedPacketSumMoney(redPacketSumMoney);
        dto.setPlatformVoucherShopPrice(platformVoucherShopPrice);
        dto.setOrderGoodsPlatformBear(orderGoodsPlatformBear);
        dto.setOrderGoodsAddPlatformBear(orderGoodsAddPlatformBear);
        dto.setPlatformVoucherRptPrice(platformVoucherRptPrice);
        dto.setPlatformVoucherRptAddPrice(platformVoucherRptAddPrice);
        dto.setCouponPrice(couponPrice);
        dto.setRedPacketGoodsSumMoney(redPacketGoodsSumMoney);
        dto.setInvoiceId(invoiceId);
        dto.setOrderId(orderId);
        dto.setInvoiceName(invoiceName);

        return  dto;
    }


    public ResponseResult insertOrderBase(CommonParameterVO cp,CreateOrderDTO dto,PriceDTO priceDTO,UserInfoVO ui,
                                   SubclassDTO subclassDTO,ShopUserMessageResultVO shopUserMessageResult,
                                   ConsumeTradeParaDTO ctp, ConsumeRecordParaDTO crp, ConsumeRecordByBusinessDTO crb,
                                   Boolean vkFlag,Integer shopId,String shopName, String orderGoodsTime,  BigDecimal shopPrice,
                                   BigDecimal orderDiscountFee, BigDecimal shippingFee,String buyerMessage, Integer districtId,
                                   HttpServletRequest request,  Map<String,Object> respData,BigDecimal totalDealerCommission,
                                   BigDecimal totalSupplyCommission,String voucherIds, List<String> orderList,
                                   Integer orderCancelMinute, ShippingListVO shippingListDTO) throws ParseException, InvocationTargetException, IllegalAccessException {
        List<Map<String, String>> totalGiveawayList = priceDTO.getTotalGiveawayList(); //获取赠品清单
        List<Map<String, String>> shopGiveawayList = new ArrayList<>(); //店铺赠品清单
        Long orderCancelTime=null;
        Integer orderGateShopId = null;
        Integer orderStatus = 1;// 订单状态
        String sellerUserName = null;
        String sellerPhone = null;
        if(null != cp.getIntegralGoods() && cp.getIntegralGoods() == 0){
            sellerUserName = "平台商铺";
            subclassDTO.setSellerId("1");
            sellerPhone = "";
        }else{
            subclassDTO.setSellerId(shopUserMessageResult.getUserId());
            sellerUserName = shopUserMessageResult.getUserName();
            sellerPhone = shopUserMessageResult.getContactsPhone();
        }
        RedisUtil.set(YFConfig.YF_SELLERPHONE + "--" + subclassDTO.getOrderId(), sellerPhone, 86400);
        String voucherId = "";
        if (!voucherIds.equals("0")) {
            voucherId = voucherIds;
        }
        // 创建订单(orderBase)
        if (null != cp.getOrderIsShopTake()) {
            dto.setOrderIsShopTake(cp.getOrderIsShopTake());
        }
        if (null != cp.getShopGateId()) {
            orderGateShopId = cp.getShopGateId();
        }
        String shareUserId = "0";
        if (vkFlag) {
            shareUserId = null == cp.getShareUserId() ? "0" : cp.getShareUserId();
        }
        // 供应商待发货订单
        if (null != subclassDTO.getSupplyShopId() && subclassDTO.getSupplyShopId().intValue() != shopId.intValue()) {
            priceDTO.setDropShipping(1);
        }
        if(dto.getPayMentCode() == 3){
            orderStatus = 3;
        }
        //查询店铺赠品 ZZZ
        if(null!=totalGiveawayList) {
            for (Map<String, String> giveawayMap : totalGiveawayList) {
                if (null != giveawayMap && null != shopId) {
                    if (null != giveawayMap.get("shopId") && (shopId.toString()).equals(giveawayMap.get("shopId"))) {
                        giveawayMap.remove("shopId");
                        shopGiveawayList.add(giveawayMap);
                    }
                }
            }
            priceDTO.setGiveawayInfo(JsonUtils.toString(shopGiveawayList));// list 转 String
            shopGiveawayList.clear();
        }

        //封装参数
        Map<String, Object> map=getStringObjectMapBase(dto,priceDTO,subclassDTO,ui,shopId,orderGateShopId,shopName,shareUserId,sellerUserName,
                                                      orderGoodsTime,shopPrice,orderDiscountFee,shippingFee,buyerMessage,orderStatus,voucherId,districtId,
                                                      request,respData,totalDealerCommission,totalSupplyCommission);

        OrderBaseEntity entity=ParseMapUtils.parseMap2Object(map,OrderBaseEntity.class);
        entity.setOrderGateShopId(orderGateShopId);

        int isInsertByorderBaseSuccess = orderBaseMapper.insert(entity);
        // consumeRecord所需参数(商家订单)
        crb.setSellId(subclassDTO.getSellerId());
        crb.setOrderId(subclassDTO.getOrderId());// 订单号
        crb.setUserName(sellerUserName);
        crb.setPaymentNumber(subclassDTO.getPaymentNumber());// 支付号
        crb.setTotalPrice(subclassDTO.getOrderBasePaymentAmount());
        payMentServiceClient.insertConsumeRecordByBusiness(crb);
        // fegin调用插入数据ConsumeRecord(买家订单)
        crp.setUserId(ui.getUserId());
        crp.setOrderId(subclassDTO.getOrderId());// 订单号
        crp.setUserName(ui.getUserName());
        crp.setPaymentNumber(subclassDTO.getPaymentNumber());// 支付号
        crp.setTotalPrice(subclassDTO.getOrderBasePaymentAmount());
        payMentServiceClient.insertConsumeRecord(crp);
        // consumeTrade所需参数
        ctp.setUserId(ui.getUserId());
        ctp.setOrderId(subclassDTO.getOrderId());// 订单号
        ctp.setSellerId(subclassDTO.getSellerId());
        ctp.setPaymentNumber(subclassDTO.getPaymentNumber());// 支付号
        ctp.setTotalPrice(subclassDTO.getOrderBasePaymentAmount());// 商品价格
        ctp.setTradeDiscount(priceDTO.getTradeDiscount());// 优惠价格
        ctp.setTotalIntegral(priceDTO.getTotalIntegral());//兑换积分商品所需的积分
        ctp.setIntegralGoods(priceDTO.getIntegralGoods());
        // fegin调用插入数据ConsumeTrade
        payMentServiceClient.insertConsumeTrade(ctp);
        orderList.add(subclassDTO.getOrderId());
        Integer count = orderBaseMapper.checkInvoiceSwitchStatus(shopId);
        if(count>0){
            if(!orderList.contains(subclassDTO.getOrderId())) {
                orderList.add(subclassDTO.getOrderId());
            }
        }
        //更新库存
        String saleSum = RedisUtil.get(YFConfig.YF_SALENUM + subclassDTO.getOrderId());
        if (null != cp.getOrderIsShopTake() && cp.getOrderIsShopTake()==1){
            businessServiceClient.updateShopGateStock(saleSum);
        }else{
            Map<String,String> param = new HashMap<>();
            param.put("saleSum",saleSum);
            goodServiceClient.updateSaleSum(param);
        }
        if (isInsertByorderBaseSuccess>0) {
            // 更改赠品库存
            if (shippingListDTO.getShopGiveawayList() != null && !shippingListDTO.getShopGiveawayList().isEmpty()) {
                List<Integer> list = shippingListDTO.getShopGiveawayList().stream().map(item -> Integer.parseInt(item.get("giveawayId"))).collect(Collectors.toList());
                goodServiceClient.updateGiveawayStock(list);
            }
            // 更改秒杀取消时间
            if (null != orderCancelMinute) {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date orderTimeTmp = simpleDateFormat.parse(orderGoodsTime);
                Calendar cal = Calendar.getInstance();
                cal.setTime(orderTimeTmp);
                cal.add(Calendar.MINUTE, orderCancelMinute);
                orderTimeTmp = cal.getTime();
                orderCancelTime = orderTimeTmp.getTime()/1000;
                Date seckillCancelTime = simpleDateFormat.parse(simpleDateFormat.format(orderTimeTmp));
                Map<String,Object> orderMap = new HashMap<>();
                orderMap.put("orderId",subclassDTO.getOrderId());
                orderMap.put("seckillCancelTime",seckillCancelTime);
                orderBaseMapper.updateSeckillCancelTime(orderMap);
            }
            return ResponseResult.success("创建成功",orderCancelTime);
        }
        else {
            return ResponseResult.fail(orderCancelTime);
        }
    }

    private Map<String, Object> getStringObjectMapBase(CreateOrderDTO dto, PriceDTO priceDTO,
                                                       SubclassDTO subclassDTO, UserInfoVO ui,
                                                       Integer shopId, Integer orderGateShopId, String shopName, String shareUserId,
                                                       String sellerUserName, String orderGoodsTime, BigDecimal shopPrice, BigDecimal orderDiscountFee,
                                                       BigDecimal shippingFee, String buyerMessage, Integer orderStatus, String voucherId, Integer districtId,
                                                       HttpServletRequest request, Map<String, Object> respData, BigDecimal totalDealerCommission, BigDecimal totalSupplyCommission) {

        Map<String, Object> map = new HashMap<>();
        //0 是虚拟订单 1 不是虚拟订单
        Integer virtualGoods = 1;
        String periodOfValidity = null;
        Integer pastDue = null;
        if (respData.containsKey("virtualGoods")) {
            virtualGoods = (Integer) respData.get("virtualGoods");
        }
        if (respData.containsKey("periodOfValidity")) {

            periodOfValidity = (String) respData.get("periodOfValidity");
        }
        if (respData.containsKey("pastDue")) {

            pastDue = (Integer) respData.get("pastDue");
        }
        map.put("orderId", subclassDTO.getOrderId());
        map.put("shopId", shopId);
        map.put("orderGateShopId ", orderGateShopId);
        map.put("shopName", shopName);
        map.put("buyerUserId", ui.getUserId());
        map.put("buyerUserName", ui.getUserName());
        map.put("sellerUserId", subclassDTO.getSellerId());
        map.put("sellerUserName", sellerUserName);
        map.put("orderDate", DateUtils.getYear() + "-" + DateUtils.getMonth() + "-" + DateUtils.getDay());
        map.put("orderCreateTime", orderGoodsTime);
        map.put("orderReceiverName", dto.getOrderReceiverName());
        map.put("orderReceiverAddress", dto.getOrderReceiverAddress());
        map.put("orderReceiverContact", dto.getOrderReceiverContact());
        map.put("orderReceiverProvinceId", dto.getOrderReceiverProvinceId());
        map.put("orderReceiverCityId", dto.getOrderReceiverCityId());
        map.put("orderReceiverAreaId", dto.getOrderReceiverAreaId());
        map.put("paymentNumber", subclassDTO.getPaymentNumber());
        map.put("orderInvoice", subclassDTO.getInvoiceName());
        map.put("invoiceId", subclassDTO.getInvoiceId());
        map.put("orderGoodsAmount", shopPrice);
        map.put("orderPaymentAmount", subclassDTO.getOrderBasePaymentAmount());
        map.put("orderDiscountFee", orderDiscountFee.add(subclassDTO.getBaseMemberDiscount()));
        map.put("orderShippingFee", shippingFee);
        map.put("orderBuyerEvaluationStatus", 0);
        map.put("orderMessage", buyerMessage);
        map.put("orderStatus", orderStatus);
        map.put("orderDiscountType", priceDTO.getOrderDiscountType());
        map.put("voucherPrice", subclassDTO.getCouponPrice());
        map.put("voucherCode", voucherId);
        map.put("orderFrom", dto.getOrderFromNum());
        map.put("redpacketCode", priceDTO.getRedpacketId());
        map.put("redpacketPrice", priceDTO.getRedPacketPrice());
        map.put("orderRptPrice", subclassDTO.getRedPacketSumMoney());
        if(subclassDTO.getRedPacketSumMoney() != null && subclassDTO.getOrderBasePaymentAmount().compareTo(BigDecimal.ZERO) == 0){
            map.put("orderRptPrice",shopPrice.subtract(subclassDTO.getBaseMemberDiscount().add(subclassDTO.getCouponPrice())));
        }
        map.put("platformCouponCode", priceDTO.getPlatformVoucherCode());
        map.put("platformCouponPrice", priceDTO.getPlatformVoucherPrice());
        map.put("platformCouponRptPrice", subclassDTO.getPlatformVoucherShopPrice());
        map.put("districtId", districtId);
        map.put("parentShopId", ui.getUserParentShopId());
        map.put("inviteSubsiteId", ui.getInviteSubsiteId());
        map.put("treasureOrderShopId", dto.getTreasureOrderShopId());
        map.put("orderPromotionId", subclassDTO.getOrderPromotionId());
        map.put("groupbuyStatus", subclassDTO.getGroupbuyStatus());
        map.put("orderBuyId", subclassDTO.getOrderBuyId());
        map.put("smallOrder", subclassDTO.getSmallOrder());
        map.put("liveId", request.getHeader("liveId"));
        map.put("accountId", request.getHeader("accountId"));
        map.put("virtualGoods", virtualGoods);
        map.put("periodOfValidity", periodOfValidity);
        map.put("pastDue", pastDue);
        map.put("shopDistributorId", 0);
        map.put("orderType", CommonType.orderType.GOODS_TYPE.getCode());
        map.put("deliverShopId", subclassDTO.getSupplyShopId());
        map.put("deliverShopName", subclassDTO.getSupplyShopName());
        map.put("orderSupplyAmount", subclassDTO.getOrderSupplyPrice());
        map.put("vkShareUserId", shareUserId);
        map.put("integralGoods", priceDTO.getIntegralGoods());
        map.put("totalIntegral", priceDTO.getTotalIntegral());
        map.put("orderIsShopTake", dto.getOrderIsShopTake());
        map.put("dropShipping", priceDTO.getDropShipping());
        map.put("dealerCommission", totalDealerCommission);
        map.put("supplyCommission", totalSupplyCommission);
        map.put("payMentCode", dto.getPayMentCode());
        map.put("manjianDiscount", priceDTO.getManjianDiscountBase());
        map.put("manzheDiscount", priceDTO.getManzheDiscountBase());
        map.put("giveawayInfo", priceDTO.getGiveawayInfo());
        map.put("orderCommissionFee", subclassDTO.getOrderBaseCommission());
        map.put("baseMemberDiscount", subclassDTO.getBaseMemberDiscount());
        map.put("plusOrder", priceDTO.getPlusOrder());
//        map.put("orderCreateTime",new Date());
//        map.put("orderGoodsAmount",priceDTO.getOrderGoodsAmount());
//        map.put("orderPaymentAmount",subclassDTO.getOrderBasePaymentAmount());


        return map;


    }

}
